Learn R Programming

rscala (version 3.2.25)

+.rscalaBridge: Declaration Operator

Description

This operator compiles and executes a snippet of Scala code in Scala's global environment, where subsequent uses of the same code snippet do not skip the time-consuming compilation step and the return value is NULL. As such, this operator is used to define global imports, objects, classes, methods, etc.

Usage

# S3 method for rscalaBridge
+(bridge, snippet)

Value

Returns NULL, invisibly.

Arguments

bridge

A Scala bridge.

snippet

String providing a Scala code snippet.

See Also

*.rscalaBridge, ^.rscalaBridge, scala

Examples

Run this code
# \donttest{
s <- scala()
s + '
  import scala.util.Random.nextInt
  import scala.math.{Pi, log, exp, sqrt}
  val const = -log(sqrt(2*Pi))
  def dnorm(x: Double, mean: Double, sd: Double, logScale: Boolean) = {
    val z = ( x - mean ) / sd
    val result = const - log(sd) - z * z / 2
    if ( logScale ) result else exp(result)
  }
'
s $ const()
s $ nextInt(100L)
s $ dnorm(8, 10, 2, FALSE)
close(s)
# }

Run the code above in your browser using DataLab