Description Usage Arguments Details Examples
This function runs Python code that is provided in a character vector.
1 |
code |
a character vector containing Python code, typically a single line with indentation and EOL characters as required by Python syntax |
stopOnException |
if |
The character vector containing the code to execute may consist of a single string with EOL and indentation characters embedded.
Alternatively, it can be a character vector, each entry containing one or more lines of Python code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | a <- 1:4
b <- 5:8
py.exec(c("def concat(a,b):", "\treturn a+b"))
py.call("concat", a, b)
# [1] 1 2 3 4 5 6 7 8
## Not run:
py.exec("raise Exception('Stop the presses!')")
# Error in py.exec("raise Exception('Stop the presses!')") (from py.exec.R#48) :
# Traceback (most recent call last):
# File "<string>", line 2, in <module>
# Exception: Stop the presses!
## End(Not run)
py.exec("raise Exception('Houston, we have a problem!')", stopOnException = FALSE)
# Warning message:
# In py.exec("raise Exception('Houston, we have a problem!')", stopOnException = FALSE) :
# Traceback (most recent call last):
# File "<string>", line 2, in <module>
# Exception: Houston, we have a problem!
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.