Learn R Programming

PythonInR (version 0.1-12)

pyTuple: Creates a virtual Python tuple

Description

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

Usage

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

Run this code
# NOT RUN {
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]
}
# }

Run the code above in your browser using DataLab