Learn R Programming

XRPython (version 0.8)

Modules: Import a Python module or add a directory to the Python Search Path

Description

If called from the source directory of a package during installation, both pythonImport and pythonAddToPath() also set up a load action for that package. The functional versions, not the methods themselves, should be called from package source files to ensure that the load actions are created.

Usage

pythonImport(..., evaluator, where = topenv(parent.frame()))

pythonAddToPath(directory = "python", package = utils::packageName(topenv(parent.frame())), pos = NA, evaluator, where = topenv(parent.frame()))

Arguments

..., where

arguments for the $Import() method. See the method documentation for details.

evaluator

The evaluator object to use. Supplying this argument suppresses the load action.

directory

the directory to add, defaults to "python"

package, pos

arguments package and pos to the method, usually omitted.

Functions

  • pythonImport: Add the module and name information specified to the objects imported for Python evaluators.

  • pythonAddToPath: Add the directory specified to the search path for future Python objects.

Examples

Run this code
# NOT RUN {
## How to search from a local directory, import a function from a file there
## and call the function.
## Including the evaluator argument causes the path change and import to happen
## right now, not in a package being loaded
ev <- RPython()
pythonAddToPath("/Users/me/myPython/", package = "",
                evaluator = ev)
pythonImport("funEx", "foo", evaluator = ev)
pythonCall("foo", 1.1, 1.2)
# }

Run the code above in your browser using DataLab