plus-.rscalaBridge: Declaration Operator

+.rscalaBridgeR Documentation

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 class 'rscalaBridge'
bridge + snippet

Arguments

bridge

A Scala bridge.

snippet

String providing a Scala code snippet.

Value

Returns NULL, invisibly.

See Also

*.rscalaBridge, ^.rscalaBridge, scala

Examples


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)



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