emzed.r_connect package

Submodules

Module contents

exception emzed.r_connect.RError(value)[source]

Bases: Exception

class emzed.r_connect.RInterpreter(r_exe=None, do_log=False, required_version='', **kw)[source]

Bases: object

This class is the bridge to R. It creates a connection to a R process, it allows code execution and passes data to and from this process. For convinience R data.frame objects are converted to and from emzed Table objects.

Example:

>>> ip = emzed.r.RInterpreter()

>>> ip.execute("a <- 3")
>>> print ip.a
3

>>> ip.execute("tab <- data.frame(a=c(1, 2), b=c(2.1, 3))")
>>> print ip.tab
<emzed.core.data_types.table.Table object at 0x.......>

>>> print ip.tab
a        b
int      float
------   ------
1        2.100000
2        3.000000

>>> print ip.get_raw("x")    # returns pandas DataFrame
   a    b
1  1  2.1
2  2  3.0
execute(*cmds, **kw)[source]

executes commands. Each command may be a multiline command. kw is used for easier string interpolation, eg

rip.execute(“x <- %(name)r”, name=”emzed”)

instead of

rip.execute(“x <- %(name)r” % dict(name=”emzed”))

execute_file(path)[source]

execute r scripts described by path

if path is only a file name the directory of the calling functions __file__ is used for looking up the r script. use “./abc.r” notation if you want to get script from the current working directory.

get_df_as_table(name, col_types=None, col_formats=None)[source]

Transfers R data.frame object with name name to emzed Table object. For the remaining paramters see from_pandas()

get_raw(name)[source]

returns data.frame as pandas DataFrame, etc. no converstion to emzed Table data structure