eval: Execute Code, Set Values, and Get Values in a Scala...

Description Usage Arguments Details Value Author(s) See Also

Description

These functions define the package's interface to an embedded Scala interpreter/compiler. Code is executed in Scala and data is passed between R and Scala. Callbacks to the original R interpreter are supported. R functions can be implemented in Scala. The result of a Scala execution can be a Scala reference or an R object.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
interpreter %@% snippet

interpreter %~% snippet
interpreter %.~% snippet

interpreter %!% snippet
interpreter %.!% snippet

scalaNull(type)

## S3 method for class 'ScalaInterpreter'
interpreter$identifier
## S3 replacement method for class 'ScalaInterpreter'
interpreter$identifier <- value

Arguments

interpreter

An interpreter from the scala function.

snippet

A character vector of arbitrary length to be evaluated by the interpreter. Multiline elements are accepted.

type

A string containing a valid Scala type, e.g., "List[Double]".

identifier

A character vector of length one containing a valid Scala identifier.

value

Either: i. a vector or matrix of integers, doubles, logicals, characters, or raw, or ii. a Scala reference.

Details

interpreter %@% snippet evaluates the expression snippet, whereas interpreter %~% snippet both evaluates the expression snippet and attempts to return a vector or matrix of integers, doubles, logicals, characters, or raw or — if this is not possible — NULL is returned. interpreter %.~% snippet has the same behavior except it always returns a Scala reference. References may be used later for assignment and Scala function arguments. Note that memory allocated as a result of assignment or executing snippet will never be garbage collected due to a limitation of Scala's REPL. (See the Scala bug detailed here: https://issues.scala-lang.org/browse/SI-4331.)

interpreter %!% snippet and interpreter %.!% snippet are the analog to interpreter %~% snippet and interpreter %~% snippet, respectively, that should only be used within a function to define a Scala function. Memory associated with the return values by function defined by interpreter %!% snippet and interpreter %.!% snippet is garbage collected. Thus, heavy usage of interpreter %!% snippet and interpreter %.!% snippet functions is encouraged for memory intensive applications. Importantly, these functions have much less invocation latency than the equivalent code using %~% and %.~%. The speed difference in invocation is especially noticeable for quick functions.

interpreter$identifier and interpreter$identifier <- value get and set variables in the interpreter.

Value

s$x tries to convert the Scala object x to a vector or matrix of integers, doubles, logicals, characters, or raw. If a conversion is not possible, a Scala reference is returned. s$.x always returns a Scala reference for the Scala object x.

s$x <- value always returns value after having set the Scala variable x to it.

function(...) s %!% snippet returns a Scala function where ... should be named arguments that can be used in the Scala code given in snippet. function(...) s %.!% snippet is the same, except a Scala reference is always returned.

scalaNull(type) returns a null reference whose Scala type is type. This can be helpful in defining Scala functions.

s$.CLASSNAME$METHODNAME(...) returns the result of calling METHODNAME in the class CLASSNAME using the unnamed, positional arguments in .... ref$METHODNAME(...) returns the result of calling METHODNAME on the Scala reference ref using the unnamed, positional arguments in .... Adding .EVALUATE=FALSE after ... will yield an optimized Scala function instead of evaluating the function. Adding .AS.REFERENCE=TRUE after ... will always yield a Scala reference.

Author(s)

David B. Dahl dahl@stat.byu.edu

See Also

scala, scalaSettings, strintrplt


rscala documentation built on Aug. 31, 2017, 1:02 a.m.