pyTuple: Creates a virtual Python tuple

Description Usage Arguments Details Examples

View source: R/PyObjectTuple.R

Description

The function pyTuple creates a virtual Python object of type PythonInR_Tuple.

Usage

1
pyTuple(key, value, regFinalizer = FALSE)

Arguments

key

a character string giving the name of the Python object.

value

an optional value, allowed values are vectors, lists and NULL.

regFinalizer

a logical indicating if a finalizer should be be registered, the default value is TRUE.

Details

If no value is provided a virtual Python tuple for an existing Python object is created. If the value is NULL an empty virtual Python object for an empty tuple is created. If the value is a vector or tuple a new Python object based on the vector or list is created.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
if ( pyIsConnected() ){
pyExec('myPyTuple = (1, 2, 5, "Hello R!")')
# create a virtual Python tuple for an existing tuple
myTuple <- pyTuple("myPyTuple")
myTuple[0]
tryCatch({myTuple[1] <- "should give an error since tuple are not mutable"},
         error = function(e) print(e))
myTuple
# create a new Python tuple and virtual tuple
newTuple <- pyTuple('myNewTuple', list(1:3, 'Hello Python'))
newTuple[1]
}

PythonInR documentation built on July 1, 2020, 6:05 p.m.