def to_rData(variable): import pandas as pd import numpy as np from rpy2.robjects import FloatVector, int2ri, StrVector from rpy2.robjects import pandas2ri pandas2ri.activate() if type(variable) == pd.core.frame.DataFrame: output = pandas2ri.py2ri(variable) elif type(variable) == np.ndarray: output = numpy2ri(variable) elif type(variable) == list: output = FloatVector(variable) elif type(variable) == int: output = int2ri(variable) elif type(variable) == str: output = StrVector(variable) pandas2ri.deactivate()
def npint_py2ri(obj): return ro.int2ri(obj)