Description Usage Arguments Details Examples
View source: R/PyObjectTuple.R
The function pyTuple creates a virtual Python object of type PythonInR_Tuple.
1 |
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. |
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.
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]
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.