These functions control whether objects from Python are automatically
converted to their R equivalents when accessed through reticulate
.
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
} # }