py.get: Get values from Python variables to R

Description Usage Arguments Value Examples

Description

py.get get the value of Python and returns it to the R environment. Objects are serialized as JSON strings on Python with json.dumps, are transferred to R and are converted back to an R value using jsonlite::fromJSON.

Usage

1
py.get(var.name, json.opt.ret = getOption("SnakeCharmR.json.opt.ret", list()))

Arguments

var.name

a character string containing a valid Python variable name

json.opt.ret

explicit arguments to pass to jsonlite::fromJSON when deserializing the value

Value

an R object containing the variable value after serialization to JSON in the Python environment and deserialization from JSON in the R environment

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
py.assign("a", 1:4)
py.get("a")
# [1] 1 2 3 4

py.assign("b", list(one = 1, foo = "bar"))
str(py.get("b"))
# List of 2
#  $ foo: chr "bar"
#  $ one: int 1

py.exec("import math")
py.get("math.pi")
# [1] 3.141593

## Not run: 
py.rm("notset")
py.get("notset")
# Error in py.get("notset") (from py.get.R#60) : Traceback (most recent call last):
#   File "<string>", line 2, in <module>
# NameError: name 'notset' is not defined

## End(Not run)

SnakeCharmR documentation built on May 2, 2019, 6:21 a.m.