rJython: rJython

Description Usage Arguments Details Value References Examples

View source: R/rJython.R

Description

Interface for using python from R via Jython

Usage

1
  rJython( jython.jar = NULL, modules = NULL )

Arguments

jython.jar

Optional alternative location of the jython.jar file. The package is distributed with its 'jython.jar' file, but the user can invoke their own by providing its path.

modules

List containing optional paths for required modules. Packages utilizing rJython can add their own extra python modules to the 'inst' directory and then add their base path using function system.file so that they can be later found when issuing 'import module' directives.

Details

This function is not primarily intended to be run directly by users but to be used by R packages with python dependencies. Their authors are invited to hide the internals of this package in their code at their convenience.

Value

An object of class rJava that can exectute python code as per the examples below.

References

http://rsympy.googlecode.com, http://www.jython.org/Project/, http://www.jython.org/javadoc/org/python/util/PythonInterpreter.html

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
27
rJython <- rJython()

# Now you can use the rJava low level interface

rJython$exec( "a = 2*2" )
four <- rJython$get("a")
.jstrVal( four )

# Alternatively, a higher level interface is provided by the rJython package:

a <- 1:4
jython.assign( rJython, "a", a )
jython.exec( rJython, "b = len( a )" )
jython.get( rJython, "b" )


## Not run: 

# If package 'foo' contains python code that depends on module 'mod',
#   'mod' can be included in the 'inst' directory of the package.
# Then, in order to make it available to Jython, the interpreter can be
#   started as follows:

rJython <- rJython( modules = system.file("python-modules", package = "foo") )


## End(Not run)

rJython documentation built on May 2, 2019, 4:55 p.m.

Related to rJython in rJython...