This function creates an instance of a Scala bridge. Details on this function (and the rscala package as a whole) are provided in the package vignette. The original paper was published in the Journal of Statistical Software. See the reference below.
scala(
JARs = character(),
serialize.output = .Platform$OS.type == "windows",
stdout = TRUE,
stderr = TRUE,
port = 0L,
heap.maximum = NULL,
command.line.arguments = character(0),
debug = FALSE
)
Returns a Scala bridge.
Character vector describing JAR files to include in the classpath. Elements are some combination of file paths to JARs or package names which contain embedded JARs. In the case of package names, the embedded JARs of all packages that recursively depend on, import, or suggest the specified package are also included.
Logical indicating whether Scala output should be serialized back to R. This is slower and probably only needed on Windows.
When serialize.output == FALSE
, this argument influences
where "standard output" results should be sent. TRUE
or ""
sends output to the R console (although that may not work on Windows).
FALSE
or NULL
discards the output. Otherwise, this is the
name of the file that receives the output.
Same as stdout
, except influences the "standard error".
If 0
, two random ports are selected. Otherwise,
port
and port+1
are used to the TCP/IP connections.
String giving Scala's heap maximum, e.g., "8G" or "512M".
The value here supersedes that from scalaMemory
. Without this
being set by either scala
or scalaMemory
, the
heap maximum will be 90% of the available RAM.
A character vector of extra command line arguments to pass to the Scala executable, where each element corresponds to one argument.
(Developer use only.) Logical indicating whether debugging should be enabled.
Multiple interpreters can be created and each runs independently with its own memory space. Each interpreter can use multiple threads/cores, but the bridge between R and Scala is itself not thread-safe, so multiple R threads/cores should not simultaneously access the same bridge.
Terminate the bridge using close.rscalaBridge
.
David B. Dahl (2019). "Integration of R and Scala Using rscala." Journal of Statistical Software, 92:4, 1-18. https://www.jstatsoft.org
close.rscalaBridge
, scalaMemory
scalaPushRegister
, scalaPullRegister
# \donttest{
s <- scala()
rng <- s $ .new_scala.util.Random()
rng $ alphanumeric() $ take(15L) $ mkString(',')
s * '2+3'
h <- s(x=2, y=3) ^ 'x+y'
h $ toString()
s(mean=h, sd=2, r=rng) * 'mean + sd * r.nextGaussian()'
close(s)
# }
Run the code above in your browser using DataLab