Next: Proc conversion, Previous: R to Python, Up: R to Python
There are five different conversion modes, identified by the
following constants (provided by the rpy
module) and another
constant to indicate the absence of a global mode:
PROC_CONVERSION
CLASS_CONVERSION
BASIC_CONVERSION
VECTOR_CONVERSION
NO_CONVERSION
NO_DEFAULT
The rpy
module provides three functions for manipulating the
conversion modes:
get_default_mode()
set_default_mode(m)
m
.
with_mode(m, fun)
fun
in the conversion mode m
. It
returns a new function which accepts the same parameters as fun
but, when called, it is evaluated in the conversion mode m
.
For example:
>>> set_default_mode(BASIC_CONVERSION) >>> r.seq(1,3) [1, 2, 3] >>> with_mode(NO_CONVERSION, r.seq)(1,3) <Robj object at 0x8acb2a0>
The result of a call to a Robj
object is converted according to
the following rules:
PROC_CONVERSION
,
CLASS_CONVERSION
, BASIC_CONVERSION
,
NO_CONVERSION
}, that mode is used.
NO_DEFAULT
, then the object's
local mode is used.
NO_CONVERSION
mode
always succeed returning a “pure” Robj
object.
At startup the default mode is set to NO_DEFAULT
, which means
that each object has its own conversion mode, and every Robj
object is retrieved with a local mode set to PROC_CONVERSION
.