CompiledScript: CompiledScript Class

Description Usage Details Value Methods See Also Examples

Description

The CompiledScript class represents script compiled by a script engine.

Usage

1

Details

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.

Value

Object of R6Class that represents a compiled script.

Methods

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.

See Also

ScriptEngine

Examples

 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()

jsr223 documentation built on July 1, 2020, 10:30 p.m.