Learn R Programming

PythonInR (version 0.1-12)

pyImport: Import virtual Python objects to R

Description

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

Usage

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

Run this code
# NOT RUN {
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")
# }

Run the code above in your browser using DataLab