Learn R Programming

rscala (version 3.1.0)

scala: Instantiate a Scala Bridge

Description

This function creates an instance of an rscala bridge.

Usage

scala(packages = character(), assign.callback = function(s) { },
  assign.name = "s", JARs = character(),
  serialize.output = .Platform$OS.type == "windows", stdout = TRUE,
  stderr = TRUE, port = 0L, heap.maximum = NULL,
  assign.env = parent.frame(), debug = FALSE)

Arguments

packages

Character vector of package names whose embedded JAR files are to be added to the classpath.

assign.callback

A function taking a Scala bridge as its only argument. This function is called immediately after the bridge is connected, which does not happen until the bridge is actually used and may be long after this function finishes. This is where setup code goes, like global imports, objects, classes, methods, etc. For example, it might equal function(s) { s + 'import scala.util.Random' }. Note the use of the execution operator + instead of the evaluation operator *.

assign.name

The name of the (promise of the) bridge to be assigned in the environment given by the assign.env argument.

JARs

Character vector whose elements are individual JAR files to be added to the runtime classpath.

serialize.output

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

stdout

Whether "standard output" results that are not serialized 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 indicating the JVM heap maximum, e.g., "8G". Without this being set in either scala or scalaHeapMaximum, the heap maximum will be 85% of the physical RAM. The value from scalaHeapMaximum supersedes that from scala.

assign.env

(Developer use only.) The environment in which the (promise of the) bridge is assigned.

debug

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

Value

Returns an rscala bridge.

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.

Rather than calling this function explicitly, packages importing or depending on rscala should instead use the scalaPackage and scalaPackageUnload functions.

See Also

close.rscalaBridge, scalaPackage, scalaPackageUnload, scalaHeapMaximum

Examples

Run this code
# NOT RUN {
scala(assign.name='e')      # Implicitly defines the bridge 'e'.
rng <- e $ .new_scala.util.Random()
rng $ alphanumeric() $ take(15L) $ mkString(',')
e * '2+3'
h <- e(x=2, y=3) ^ 'x+y'
h $ toString()
e(mean=h, sd=2, r=rng) * 'mean + sd * r.nextGaussian()'
close(e)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab