How to use the rpy2.robjects.conversion.py2rpy function in rpy2

To help you get started, we’ve selected a few rpy2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rpy2 / rpy2 / tests / robjects / test_conversion_numpy.py View on Github external
def check_homogeneous(self, obj, mode, storage_mode):
        converted = conversion.py2rpy(obj)
        assert r["mode"](converted)[0] == mode
        assert r["storage.mode"](converted)[0] == storage_mode
        assert list(obj) == list(converted)
        assert r["is.array"](converted)[0] is True
        return converted
github rpy2 / rpy2 / tests / robjects / test_pandas_conversions.py View on Github external
def test_series_issue264(self):
        Series = pandas.core.series.Series
        s = Series(('a', 'b', 'c', 'd', 'e'),
                   index=pandas.Int64Index([0,1,2,3,4]))
        with localconverter(default_converter + rpyp.converter) as cv:
            rp_s = robjects.conversion.py2rpy(s)
        # segfault before the fix
        str(rp_s)
        assert isinstance(rp_s, rinterface.StrSexpVector)
github rpy2 / rpy2 / tests / robjects / test_pandas_conversions.py View on Github external
def test_series_obj_mixed(self):
        Series = pandas.core.series.Series
        s = Series(['x', 1, False], index=['a', 'b', 'c'])
        with localconverter(default_converter + rpyp.converter) as cv:
            with pytest.raises(ValueError):
                rp_s = robjects.conversion.py2rpy(s)

        s = Series(['x', 1, None], index=['a', 'b', 'c'])
        with localconverter(default_converter + rpyp.converter) as cv:
            with pytest.raises(ValueError):
                rp_s = robjects.conversion.py2rpy(s)
github rpy2 / rpy2 / tests / robjects / test_pandas_conversions.py View on Github external
def test_object2String_with_None(self):
        series = pandas.Series([None, "a","b","c","a"], dtype="O")
        with localconverter(default_converter + rpyp.converter) as cv:
            rp_c = robjects.conversion.py2rpy(series)
            assert isinstance(rp_c, rinterface.StrSexpVector)
github rpy2 / rpy2 / tests / robjects / test_conversion_numpy.py View on Github external
def test_scalar(self):
        i32 = numpy.int32(100)
        i32_r = conversion.py2rpy(i32)
        i32_test = numpy.array(i32_r)[0]
        assert i32 == i32_test

        i64 = numpy.int64(100)
        i64_r = conversion.py2rpy(i64)
        i64_test = numpy.array(i64_r)[0]
        assert i64 == i64_test
github cs224 / pybnl / pybnl / bn.py View on Github external
def constrained_base_structure_learning_si_hiton_pc(ldf, test="mc-mi", undirected=False):
    rhitonpcfn = rpy2.robjects.r['si.hiton.pc']
    with rpy2.robjects.conversion.localconverter(ro.default_converter + rpy2.robjects.pandas2ri.converter):
        return rhitonpcfn(ro.conversion.py2rpy(ldf), test=test, undirected=undirected)
github rpy2 / rpy2 / rpy2 / robjects / vectors.py View on Github external
:param sep: separator character
        :param quote: quote character
        :param row_names: column name, or column index for column names
           (warning: indexing starts at one in R)
        :param fill: boolean (fill the lines when less entries than columns)
        :param comment_char: comment character
        :param na_strings: a list of strings which are interpreted to be NA
           values
        :param as_is: boolean (keep the columns of strings as such, or turn
           them into factors)
        """
        path = conversion.py2rpy(path)
        header = conversion.py2rpy(header)
        sep = conversion.py2rpy(sep)
        quote = conversion.py2rpy(quote)
        dec = conversion.py2rpy(dec)
        if row_names is not rinterface.MissingArg:
            row_names = conversion.py2rpy(row_names)
        if col_names is not rinterface.MissingArg:
            col_names = conversion.py2rpy(col_names)
        fill = conversion.py2rpy(fill)
        comment_char = conversion.py2rpy(comment_char)
        as_is = conversion.py2rpy(as_is)
        na_strings = conversion.py2rpy(na_strings)
        res = DataFrame._read_csv(path,
                                  **{'header': header, 'sep': sep,
                                     'quote': quote, 'dec': dec,
                                     'row.names': row_names,
                                     'col.names': col_names,
                                     'fill': fill,
                                     'comment.char': comment_char,
                                     'na.strings': na_strings,
github rpy2 / rpy2 / rpy2 / robjects / robject.py View on Github external
def __setitem__(self, key, value):
        rpy2_value = conversion.py2rpy(value)
        self._robj.do_slot_assign(key, rpy2_value)
github rpy2 / rpy2 / rpy2 / robjects / vectors.py View on Github external
def __lt__(self, x):
        res = globalenv_ri.find('<')(self._parent, conversion.py2rpy(x))
        return conversion.rpy2py(res)
github theislab / anndata2ri / anndata2ri / py2r.py View on Github external
dict_converter.py2rpy.register(np.bool_, lambda x: conversion.py2rpy(bool(x)))
dict_converter.py2rpy.register(np.int_, lambda x: conversion.py2rpy(int(x)))