pyGet: Gets Python objects by name and transforms them into R...

Description Usage Arguments Details Value Note Examples

View source: R/PyGet.R

Description

The function pyGet gets Python objects by name and transforms them into R objects.

Usage

1
pyGet(key, autoTypecast = TRUE, simplify = TRUE)

Arguments

key

a string specifying the name of a Python object.

autoTypecast

an optional logical value, default is TRUE, specifying if the return values should be automatically typecasted if possible.

simplify

an optional logical value, if TRUE R converts Python lists into R vectors whenever possible, else it translates Python lists always into R lists.

Details

Since any Python object can be transformed into one of the basic data types it is up to the user to do so up front. More information about the type conversion can be found in the README file or at http://pythoninr.bitbucket.org/.

Value

Returns the specified Python object converted into an R object if possible, else a virtual Python object.

Note

pyGet always returns a new object, if you want to create a R representation of an existing Python object use pyGet0 instead.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## get a character of length 1
pyGet("__name__")
## get a character of length 1 > 1
pyGet("sys.path")
## get a list
pyGet("sys.path", simplify = FALSE)
## get a PythonInR_List
x <- pyGet("sys.path", autoTypecast = FALSE)
x
class(x)

## get an object where no specific transformation to R is defined
## this example also shows the differnces between pyGet and pyGet0
pyExec("import datetime")
## pyGet creates a new Python variable where the return value of pyGet is
## stored the name of the new reference is stored in x$.name.
x <- pyGet("datetime.datetime.now().time()")
x
class(x)
x$.name
## pyGet0 never creates a new Python object, objects which can be transformed 
## to R objects are transformed. For all other objects an PythonInR_Object is created.
y <- pyGet0("datetime.datetime.now().time()")
y
## An important difference is that the evaluation of x always will return the same
## time, the evaluation of y always will give the new time.

PythonInR documentation built on May 2, 2019, 5:17 p.m.