pyImport: Import virtual Python objects to R

Description Usage Arguments Details Examples

View source: R/PyImport.R

Description

A convenience function to call the Python function import and creating virtual Python objects for the imported objects in R.

Usage

1
pyImport(import, from = NULL, as = NULL, env = parent.frame())

Arguments

import

a character giving the names of the objects to import.

from

an optional character string giving the name of the module.

as

an optional string defining an alias for the module name.

env

an optional environment where the virtual Python objects are assigned to.

Details

The function pyImport works like the import function in Python.

The function pyImport has a special behavior for the packages numpy and pandas. For these two packages pyImport does not only import numpy but also register their alias in pyOptions. To be found when pySet is used with the option useNumpy set to TRUE.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
pyImport("os")
## Not run: 
#NOTE: The following does not only import numpy but also register the
#      alias in the options under the name "numpyAlias". 
#      The same is done for pandas, the default alias for pandas and numpy 
#      are respectively "pandas" and "numpy". The numpyAlias is used 
#      when calling pySet with the pyOption useNumpy set to TRUE.
pyOptions("numpyAlias")
pyImport("numpy", as="np")
pyOptions("numpyAlias")
pyImport("pandas", as="pd")
pyImport(c("getcwd", "sep"), from="os")
getcwd()
sep
sep = "Hello R!"
pyExecp("sep")

## End(Not run)

PythonInR documentation built on July 1, 2020, 6:05 p.m.