+.rscalaBridge | R Documentation |
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.
## S3 method for class 'rscalaBridge'
bridge + snippet
bridge |
A Scala bridge. |
snippet |
String providing a Scala code snippet. |
Returns NULL
, invisibly.
*.rscalaBridge
, ^.rscalaBridge
,
scala
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.