import: Import a Python module
Description
Import the specified Python module for calling from R.
Usage
import(module, as = NULL, convert = TRUE, delay_load = FALSE)import_main(convert = TRUE)
import_builtins(convert = TRUE)
import_from_path(module, path = ".", convert = TRUE)
Arguments
as
Alias for module name (affects names of R classes). Note that
this is an advanced parameter that should generally only be used
in package development (since it affects the S3 name of the imported
class and can therefore interfere with S3 method dispatching).
convert
TRUE
to automatically convert Python objects to their R
equivalent. If you pass FALSE
you can do manual conversion using the
py_to_r()
function.
delay_load
TRUE
to delay loading the module until it is first used.
FALSE
to load the module immediately. If a function is provided then it
will be called once the module is loaded. If a list containing on_load()
and on_error(e)
elements is provided then on_load()
will be called on
successful load and on_error(e)
if an error occurs.
Details
The import_from_path
function imports a Python module from an
arbitrary filesystem path (the directory of the specified python script is
automatically added to the sys.path
).
Examples
Run this code# NOT RUN {
main <- import_main()
sys <- import("sys")
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab