Reference

rwrapr package

rwrapr.convert_py2r module

convert_py2r(x)
Return type:

FloatVector | IntVector | ListVector | Array | FactorVector | Matrix | BoolVector | StrVector | int | bool | str | float | Any

Parameters:

x (Any)

convert_py_args2r(args, kwargs)
Return type:

None

Parameters:
  • args (list[Any])

  • kwargs (dict[str, Any])

rwrapr.convert_r2py module

convert_r2py(x, ignore_s3=False)
Return type:

Any

Parameters:
  • x (Any)

  • ignore_s3 (bool)

rwrapr.function_wrapper module

rfunc(name)
Return type:

Callable[..., RView | RArray | RDataFrame | RFactor | RList | RDict | Any]

Parameters:

name (str)

wrap_rfunc(func, name)
Return type:

Callable[..., RView | RArray | RDataFrame | RFactor | RList | RDict | Any]

Parameters:
  • func (Callable[[...], Any])

  • name (str | None)

rwrapr.lazy_rexpr module

class Lazily(expr)

Bases: object

Parameters:

expr (str)

lazy_wrap(args, kwargs, func, func_name)
Return type:

Callable[..., Any] | Any

Parameters:
  • args (list[Any])

  • kwargs (dict[str, Any])

  • func (Callable[[...], Any])

  • func_name (str | None)

rwrapr.library module

importr(env_name, interactive=True)

Load an R environment (package) into the current Python session.

This function is an alias for library(), used to load an R package and create an R environment in Python using the Renv class.

Parameters:
  • env_name (str) – The name of the R package to load.

  • interactive (bool) – If True, interactively prompts the user to install missing R packages. Defaults to True.

Returns:

The loaded R environment.

Return type:

Renv

library(env_name, interactive=True)

Load an R environment (package) into the current Python session.

This function attempts to load an R package and create an R environment using the Renv class. If the package is not installed and interactive is set to False, it returns an uninitialized Renv object.

Parameters:
  • env_name (str) – The name of the R package to load.

  • interactive (bool) – If True, interactively prompts the user to install missing R packages. Defaults to True.

Returns:

The loaded R environment.

Return type:

Renv

Raises:

rpkg.PackageNotInstalledError – If the R package is not installed and interactive is set to True.

rwrapr.load_namespace module

load_base_envs()
Return type:

dict[str, InstalledSTPackage | InstalledPackage | Package]

try_load_namespace(namespace, verbose=False, hide_r_ouptut=True, interactive=True)
Return type:

Package

Parameters:
  • namespace (str)

  • verbose (bool)

  • hide_r_ouptut (bool)

  • interactive (bool)

rwrapr.nputils module

np_collapse(x, sep='_')
Return type:

str

Parameters:
  • x (ndarray[tuple[int, ...], dtype[str_]])

  • sep (str)

np_contains(x, pattern)
Return type:

bool

Parameters:
  • x (ndarray[tuple[int, ...], dtype[Any]])

  • pattern (Any)

rwrapr.rarray module

class RArray(rdata)

Bases: ndarray[Any, Any]

Parameters:

rdata (Any)

Return type:

RArray

to_py()
Return type:

ndarray[tuple[int, ...], dtype[Any]]

to_r()
Return type:

Any

convert_numpy(x, flatten=False)
Return type:

ndarray[tuple[int, ...], dtype[Any]] | int | str | float | bool | None

Parameters:
  • x (Vector | ndarray[tuple[int, ...], dtype[Any]] | NULLType | Any)

  • flatten (bool)

convert_numpy1D(x)
Return type:

Any

Parameters:

x (ndarray[tuple[int, ...], dtype[Any]])

convert_numpy2D(x)
Return type:

Any

Parameters:

x (ndarray[tuple[int, ...], dtype[Any]])

convert_numpy2r(x)
Return type:

Any

Parameters:

x (ndarray[tuple[int, ...], dtype[Any]])

convert_numpyND(x)
Return type:

Any

Parameters:

x (ndarray[tuple[int, ...], dtype[Any]])

filter_numpy(x, flatten)
Return type:

ndarray[tuple[int, ...], dtype[Any]] | int | str | float | bool

Parameters:
  • x (ndarray[tuple[int, ...], dtype[Any]])

  • flatten (bool)

get_attributes_array(x)
Return type:

dict[str, Any] | None | Any

Parameters:

x (Any)

get_rarray(x)
Return type:

RArray | bool | int | str | float

Parameters:

x (Any)

is_valid_numpy(x)
Return type:

bool

Parameters:

x (ndarray[tuple[int, ...], dtype[Any]])

rwrapr.rattributes module

attributes2r(attrs)
Return type:

dict[str, Any]

Parameters:

attrs (dict[str, Any] | None | RDict)

get_rattributes(x, exclude=None)
Return type:

Any

Parameters:
  • x (Any)

  • exclude (list[str] | None)

structure(x, **kwargs)
Return type:

Any

Parameters:
  • x (Any)

  • kwargs (Any)

rwrapr.rdataframe module

class RDataFrame(data_frame)

Bases: DataFrame

Parameters:

data_frame (DataFrame | DataFrame)

to_py()
Return type:

DataFrame

to_r()
Return type:

DataFrame

attempt_pandas_conversion(data)
Return type:

RDataFrame | TypeError

Parameters:

data (Any)

get_attributes_dataframe(df)
Return type:

dict[str, Any] | None | Any

Parameters:

df (DataFrame)

pandas2r(df)
Return type:

DataFrame

Parameters:

df (DataFrame)

r2pandas(df)
Return type:

DataFrame

Parameters:

df (DataFrame)

rwrapr.renv module

class Renv(env_name, interactive=True)

Bases: object

Represents an R environment in Python for interacting with R packages, functions, and datasets. Functions and datasets are loaded/attached to the environment dynamically. If a function or dataset is not found in the environment, it is searched for in the global R environment.

Parameters:
  • env_name (str | None)

  • interactive (bool)

__base_lib

The loaded R package.

Type:

rpkg.Package | None

__rfuncs

The set of R functions available in the environment.

Type:

set[str] | None

__rdatasets

The set of R datasets available in the environment.

Type:

set[str] | None

NULL

Equivalent to R’s NULL.

Type:

Any

NA

Equivalent to R’s NA.

Type:

Any

NaN

Equivalent to R’s NaN.

Type:

Any

Inf

Equivalent to R’s Inf.

Type:

Any

nInf

Equivalent to R’s -Inf.

Type:

Any

function(expr)

Creates a Python function from an R expression.

Parameters:

expr (str) – The R expression to convert into a function.

Returns:

A Python function equivalent to the R function.

Return type:

Callable[…, Any]

Raises:

ValueError – If the R expression does not correspond to a function.

print(x)

Prints an object as it would be printed in R.

Parameters:

x (Any) – The object to print.

Return type:

None

rclass(x)

Gets the class of an object as it would be in R.

Parameters:

x (Any) – The object to get the class of.

Returns:

The class of the object as in R.

Return type:

RReturnType

reval(expr, rview=None)

Evaluates an R expression.

Parameters:
  • expr (str) – The R expression to evaluate.

  • rview (bool | None) – If True, returns the result as an RView object, else as a Python object. Defaults to None. If None, the value of settings.rview_mode is used.

Returns:

The result of the R expression, depends on rview argument and setting.

Return type:

Any

rscript(path=None, code=None, extract=None)

Evaluates an R script. If extract is provided, extracts the specified objects from the R environment. If path is provided, reads the R script from the file. Else if code is provided, evaluates the R code directly. code and path cannot be provided at the same time.

Parameters:
  • path (str | pathlib.Path | None) – The path to the R script to evaluate. Defaults to None.

  • code (str | None) – The R code to evaluate. Defaults to None.

  • extract (list[str]) – A list of objects to extract from the R environment.

Raises:

ValueError – If both path and code are provided or if neither path nor code is provided.

Returns:

The extracted objects from the R environment. If no objects are extracted, returns None. if rview_mode is False, returns an RDict object, else returns the extracted objects as RView object.

Return type:

None | RDict | Any

fetch_data(dataset, module)
Return type:

DataFrame | RView | None

Parameters:
  • dataset (str)

  • module (Package | None)

get_assets(env_name, module)
Return type:

tuple[set[str], set[str]]

Parameters:
  • env_name (str)

  • module (Package | None)

rwrapr.rfactor module

class RFactor(r_factor)

Bases: Series

Parameters:

r_factor (FactorVector)

to_py()
Return type:

Series

to_r()
Return type:

FactorVector | Any

convert_categorical2r(series)
Return type:

FactorVector | Any

Parameters:

series (Series)

convert_rfactor2py(r_factor)
Return type:

Series

Parameters:

r_factor (FactorVector)

get_attributes_factor(df)
Return type:

dict[str, Any] | None | Any

Parameters:

df (FactorVector)

rwrapr.rlist module

class RDict(x, attributes)

Bases: UserDict[str, Any]

Parameters:
  • x (Any)

  • attributes (dict[str, Any] | None)

to_py()
Return type:

dict[str, Any]

to_r()
Return type:

Any

class RList(x, attributes)

Bases: UserList[Any]

Parameters:
  • x (Any)

  • attributes (dict[str, Any] | None)

to_py()
Return type:

list[Any]

to_r()
Return type:

Any

convert_r2pydict(x_collection, is_rdict=False)
Return type:

Any

Parameters:
  • x_collection (dict[str, Any] | OrderedDict[str, Any] | UserDict[str, Any] | RDict)

  • is_rdict (bool)

convert_r2pylist(x_collection)
Return type:

list[Any] | tuple[Any]

Parameters:

x_collection (list[Any] | tuple[Any] | set[Any] | RList)

convert_rlist2py(x_collection)
Return type:

Any

Parameters:

x_collection (ListVector | ListSexpVector)

dict2rlist(x)
Return type:

ListVector

Parameters:

x (dict[str, Any] | OrderedDict[str, Any] | UserDict[str, Any] | RDict)

is_rlist(x_collection)
Return type:

bool

Parameters:

x_collection (Any)

pylist2rlist(x)
Return type:

ListVector

Parameters:

x (list[Any] | tuple[Any] | set[Any] | RList)

rwrapr.rutils module

as_matrix(x)
Return type:

ndarray[tuple[int, ...], dtype[Any]] | Any

Parameters:

x (Any)

get_rclass(x)
Return type:

ndarray[tuple[int, ...], dtype[str_]] | None

Parameters:

x (Any)

has_unsupported_rclass(x)
Return type:

bool

Parameters:

x (Any)

is_na(x)
Return type:

bool

Parameters:

x (Any)

rcall(expr)
Return type:

Any

Parameters:

expr (str)

rwrapr.rview module

class RView(robj)

Bases: object

Parameters:

robj (Any)

to_py(ignore_s3=False)
Return type:

Any

Parameters:

ignore_s3 (bool)

to_r()
Return type:

Any

convert_s4(x)
Return type:

Any

Parameters:

x (RS4)

rwrapr.settings module

class Settings

Bases: object

Return type:

Settings

set_rview_mode(rview_mode)

Set the rview_mode attribute to the specified value.

This method updates the rview_mode attribute to control whether the RView mode is enabled or disabled. If True, Rview mode is enabled; if False, Rview mode is disabled. If Rview is True, then only Views of R objects will be displayed in the console. Otherwise, rwrapr will try to convert the R object to a Python object and display it.

Parameters:

rview_mode (bool) – A boolean value indicating whether to enable (True) or disable (False) RView mode.

Return type:

None

rwrapr.sparse module

convert_pysparsematrix(x)
Return type:

Any

Parameters:

x (coo_array | coo_matrix)

rwrapr.utils module

class ROutputCapture

Bases: object

capture_r_output()
Return type:

None

reset_r_output()
Return type:

None

pinfo(message, verbose=True)
Return type:

None

Parameters:
  • message (str)

  • verbose (bool)