scala: Instantiate a Scala Bridge

View source: R/scala.R

scalaR Documentation

Instantiate a Scala Bridge

Description

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.

Usage

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
)

Arguments

JARs

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.

serialize.output

Logical indicating whether Scala output should be serialized back to R. This is slower and probably only needed on Windows.

stdout

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.

stderr

Same as stdout, except influences the "standard error".

port

If 0, two random ports are selected. Otherwise, port and port+1 are used to the TCP/IP connections.

heap.maximum

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.

command.line.arguments

A character vector of extra command line arguments to pass to the Scala executable, where each element corresponds to one argument.

debug

(Developer use only.) Logical indicating whether debugging should be enabled.

Details

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.

Value

Returns a Scala bridge.

References

David B. Dahl (2019). "Integration of R and Scala Using rscala." Journal of Statistical Software, 92:4, 1-18. https://www.jstatsoft.org

See Also

close.rscalaBridge, scalaMemory scalaPushRegister, scalaPullRegister

Examples


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)



rscala documentation built on Aug. 15, 2023, 9:07 a.m.