Learn R Programming

rscala (version 3.2.25)

^.rscalaBridge: Evaluation Operator Returning a Reference and Transcompile Operator

Description

This operator is equivalent to *.rscalaBridge, except the return value is always an rscala reference. This operator also allows (a small subset of) R code to be transcompiled to Scala code and produces an rscala reference to an anonymous Scala function.

Usage

# S3 method for rscalaBridge
^(bridge, snippet)

Value

Returns an rscala reference.

Arguments

bridge

A Scala bridge.

snippet

String providing a Scala code snippet.

See Also

*.rscalaBridge, +.rscalaBridge, scala

Examples

Run this code
# \donttest{
s <- scala()
x <- s ^ 'new scala.util.Random()'  # These two lines ...
x <- s $ .new_scala.util.Random()   # ... are equivalent
s(rng=x) * 'rng.nextDouble()'
f <- s ^ function(x=scalaType('Double')) { pi - x }
f$apply(3.14)
s(n=10L, mapper=s ^ function(x=scalaType("Int")) { 2 * x }) * "Array.tabulate(n)(mapper)"
logStdNormalDensity <- s ^ function(x=scalaType("Double"), mean=0.0, sd=1.0) {
  variance <- sd^2
  -0.5*log(2*pi*variance) - 0.5/variance * (x-mean)^2
}
identical(logStdNormalDensity$apply(1.0), dnorm(1.0, log=TRUE))
close(s)
# }

Run the code above in your browser using DataLab