pithon.assign: Assign and get variables in Python from R

Description Usage Arguments Details Value References Examples

View source: R/pithon.assign.R

Description

Functions that assign and get Python variables from R.

Usage

1
2
  pithon.assign( var.name, value, ..., instance.name="" )
  pithon.get( var.name, instance.name="" )

Arguments

var.name

a character string containing a Python variable name

value

an R object whose equivalent will be assigned to the variable in Python

...

arguments to pass to RJSONIO's toJSON function

instance.name

if specified, use the Python instance with this name

Details

These functions can assign values to variables in Python as well as get their values back to R. Objects are serialized as JSON strings while being transferred between R and Python.

Value

Function pithon.get returns a R version of the Python variable py.var.

References

http://code.google.com/p/simplejson

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
if (pithon.available())
{
	a <- 1:4
	pithon.assign( "a", a )
	pithon.exec( "b = len( a )" )
	pithon.get( "b" )

	pithon.exec( "import math" )
	p <- pithon.get( "math.pi" )

} else {
	print("Unable to execute python")
}

pithon.set.executable("python3", instance.name="v3")
if (pithon.available("v3"))
{
	pithon.assign("x", 123.456, instance.name="v3")
	pithon.get("x", "v3")

} else {
	print("Unable to execute python3")
}

rPithon documentation built on May 2, 2019, 5:51 p.m.