Description Usage Details Value Methods See Also Examples
The CompiledScript
class represents script compiled by a script engine.
1 |
CompiledScript does not have a public constructor. Create an instance of this class with the ScriptEngine
methods compile
and compileSource
.
The complete jsr223 documentation can be found in the User Manual.
Object of R6Class
that represents a compiled script.
eval(discard.return.value = FALSE, bindings = NULL)
Executes the compiled code referenced by the object. If discard.return.value = FALSE
, the method returns the result of the last expression in the script, if any, or NULL
otherwise. The bindings
argument accepts an R named list. The name/value pairs in the list replace the script engine's global bindings during script execution.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | library("jsr223")
engine <- ScriptEngine$new("javascript")
# Compile a code snippet.
cs <- engine$compile("c + d")
# This line would throw an error because 'c' and 'd' have not yet been declared.
## cs$eval()
engine$c <- 2
engine$d <- 3
cs$eval()
## 5
# Supply new bindings...
lst <- list(c = 6, d = 7)
cs$eval(bindings = lst)
## 13
# When 'bindings' is not specified, the script engine reverts to the original
# environment.
cs$eval()
## 5
# The following line executes the code but discards the return value.
cs$eval(discard.return.value = TRUE)
# Terminate the engine.
engine$terminate()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.