Description Usage Arguments Details Examples
The function pySet allows to assign R objects to the Python namespace, the conversion from R to Python is done automatically.
1 2 |
key |
a string specifying the name of the Python object. |
value |
a R object which is assigned to Python. |
namespace |
a string specifying where the key should be located. If the namespace is set to "__main__" the key will be set to the global namespace. But it is also possible to set attributes of objects e.g. the attribute name of the object 'os'. |
useSetPoly |
an optional logical, giving if pySetPoly should be used to transform R objects into Python objects. For example if useSetPoly is TRUE unnamed vectors are transformed to Python objects of type PrVector else to lists. |
useNumpy |
an optional logical, default is FALSE, to control if numpy should be used for the type conversion of matrices. |
usePandas |
an optional logical, default is FALSE, to control if pandas should be used for the type conversion of data frames. |
More information about the type conversion can be found in the README file or at http://pythoninr.bitbucket.org/.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | pySet("x", 3)
pySet("M", diag(1,3))
pyImport("os")
pySet("name", "Hello os!", namespace="os")
## In some situations it can be beneficial to convert R lists or vectors
## to Python tuple instead of lists. One way to accomplish this is to change
## the class of the vector to "tuple".
y <- c(1, 2, 3)
class(y) <- "tuple"
pySet("y", y)
## pySet can also be used to change values of objects or dictionaries.
asTuple <- function(x) {
class(x) <- "tuple"
return(x)
}
pyExec("d = dict()")
pySet("myTuple", asTuple(1:10), namespace="d")
pySet("myList", as.list(1:5), namespace="d")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.