Learn R Programming

reticulate (version 1.3)

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, delay_load = FALSE)

Arguments

module

Module name

as

Alias for module name (affects names of R classes)

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.

path

Path to import from

Value

A Python module

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