Skip to contents

These functions control whether objects from Python are automatically converted to their R equivalents when accessed through reticulate.

Usage

py_convert_on(obj)

py_convert_off(obj)

Arguments

obj

Environment. A Python object proxy as returned by reticulate. Must be an R environment representing a Python object.

Value

Invisibly returns env with its convert flag updated.

Details

  • py_convert_on() enables automatic conversion for a given Python object.

  • py_convert_off() disables automatic conversion for a given Python object.

The obj must be a Python object proxy (typically a module, class instance, or similar R environment created by reticulate).

Examples

if (FALSE) { # \dontrun{
# Assume `np` is a Python module (NumPy)
np <- reticulate::import("numpy", convert = FALSE)

# Turn conversion on
py_convert_on(np)
np$array(c(1,2,3)) |> class()  # returns R array

# Turn conversion off
py_convert_off(np)
np$array(c(1,2,3)) |> class()  # returns Python object
} # }