MizerREnvironment

MizerREnvironment(package_name='mizer')

Thin wrapper around the embedded R session used by pymizer.

Most users should access the shared singleton via :func:get_environment rather than instantiating this class directly.

Examples

import pymizer as mz

env = mz.get_environment()
print(env.versions())

Methods

Name Description
call Call an exported R function from the mizer package.
class_name Return the first class name for an R object.
clone Return a deep copy of an R object via serialize/unserialize.
compatibility_report Return a compatibility report for the active runtime environment.
dataframe_from_r Convert an R object to a pandas DataFrame via as.data.frame().
eval Evaluate arbitrary R code in a temporary environment.
function_exists Return whether a function name resolves in the active R session.
is_s4 Return whether an object is an S4 object.
read_rds Read an .rds file and optionally wrap recognised mizer objects.
save_rds Save an R object to an .rds file.
slot_names Return slot names for an S4 object.
versions Return version information for the active Python and R bridge stack.
wrap Wrap recognised raw R objects as pymizer model classes.

call

MizerREnvironment.call(name, *args, **kwargs)

Call an exported R function from the mizer package.

Parameters

Name Type Description Default
name str Exported function name in the R package. required
*args Any Positional arguments passed to the R function. ()
**kwargs Any Keyword arguments passed to the R function. {}

Returns

Name Type Description
Any The raw R object returned by the function call.

Raises

Name Type Description
MizerError If the function is missing or the R call fails.

class_name

MizerREnvironment.class_name(obj)

Return the first class name for an R object.

clone

MizerREnvironment.clone(obj)

Return a deep copy of an R object via serialize/unserialize.

compatibility_report

MizerREnvironment.compatibility_report()

Return a compatibility report for the active runtime environment.

dataframe_from_r

MizerREnvironment.dataframe_from_r(obj)

Convert an R object to a pandas DataFrame via as.data.frame().

eval

MizerREnvironment.eval(code, /, **bindings)

Evaluate arbitrary R code in a temporary environment.

Parameters

Name Type Description Default
code str R code to evaluate. required
**bindings Any Temporary variables exposed to the evaluation environment. Python arrays and pandas objects are converted to R using the active rpy2 converters. Wrapped pymizer objects contribute their underlying R object via the .r property automatically. {}

Returns

Name Type Description
Any The raw R object returned by the final expression in code.

Raises

Name Type Description
MizerError If the code cannot be parsed or evaluated.

function_exists

MizerREnvironment.function_exists(name)

Return whether a function name resolves in the active R session.

is_s4

MizerREnvironment.is_s4(obj)

Return whether an object is an S4 object.

read_rds

MizerREnvironment.read_rds(path, *, wrap=False)

Read an .rds file and optionally wrap recognised mizer objects.

save_rds

MizerREnvironment.save_rds(obj, path)

Save an R object to an .rds file.

slot_names

MizerREnvironment.slot_names(obj)

Return slot names for an S4 object.

versions

MizerREnvironment.versions()

Return version information for the active Python and R bridge stack.

Returns

Name Type Description
dict[str, str] A mapping with entries for pymizer, Python, rpy2, R, and
dict[str, str] mizer.

wrap

MizerREnvironment.wrap(obj)

Wrap recognised raw R objects as pymizer model classes.