1. Embedding Scala in R
[david@david-centos6 ~]$ R
Instantiating a Scala interpreter/compiler in R is accomplished as follows:
R> library("jvmr")
R> a < - scalaInterpreter()
Multiple interpreters can be created and each maintains its own workspace and memory.
Scala code can be evaluated using the interpret function or its shorthand equivalent. The
following two lines of code are equivalent:
R> interpret(a,'val mu = 3')
R> a['val mu = 3']
Both the interpret function and its shorthand are capable of handling multi-line code:
R> a["val sigma = 2.5
val n = 10
"]
2. Embedding R in Scala
> JVMR_JAR=$(R --slave -e 'library("jvmr"); cat(.jvmr.jar)')
> scala -cp ".:$JVMR_JAR"
scala> import org.ddahl.jvmr.RInScala
import org.ddahl.jvmr.RInScala
scala> val R = RInScala()
R: org.ddahl.jvmr.RInScala = org.ddahl.jvmr.RInScala@40726e15
scala> R.eval("words <- his="" in="" made="" r="" span="" string="" was="">->
scala> println(R.capture("words"))
[1] "This String was made in R"
3. Embedding Spark in R
No comments:
Post a Comment