class RClient extends Dynamic
An interface to an R interpreter.
An object R
is the instance of this class available in a Scala interpreter created by calling the function
scala
from the package rscala. It is through this instance R
that
callbacks to the original R interpreter are possible.
In a Scala application, an instance of this class is created using its companion object. See below. The paths of the
rscala's JARs (for all supported versions of Scala) are available from R using rscala::.rscalaJar()
.
To get just the JAR for Scala 2.12, for example, use rscala::.rscalaJar("2.12")
.
This class is threadsafe.
val R = org.ddahl.rscala.RClient() val a = R.evalD0("rnorm(8)") val b = R.evalD1("rnorm(8)") val c = R.evalD2("matrix(rnorm(8),nrow=4)") R.set("ages", Array(4,2,7,9)) R.ages = Array(4,2,7,9) println(R.getI1("ages").mkString("<",", ",">")) R eval """ v <- rbinom(8,size=10,prob=0.4) m <- matrix(v,nrow=4) """ val v1 = R.get("v") val v2 = R.get("v")._1.asInstanceOf[Array[Int]] // This works, but is not very convenient val v3 = R.v._1.asInstanceOf[Array[Int]] // Slightly better val v4 = R.getI0("v") // Get the first element of R's "v" as a Int val v5 = R.getI1("v") // Get R's "v" as an Array[Int] val v6 = R.getI2("m") // Get R's "m" as an Array[Array[Int]]
- Alphabetic
- By Inheritance
- RClient
- Dynamic
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
cached(identifier: String): Any
For rscala developers only: Returns a value previously cached for the R interpreter.
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
debug: Boolean
For rscala developers only: Returns
TRUE
if debugging output is enabled. -
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
eval(snippet: String): Unit
Calls
eval(snippet,true)
. -
def
eval(snippet: String, evalOnly: Boolean, asReference: Boolean): (Any, String)
Evaluates
snippet
in the R interpreter.Evaluates
snippet
in the R interpreter.Returns
null
ifevalOnly
. If!evalOnly
, the last result of the R expression is returned. The result is converted ifasReference
isfalse
and the conversion is supported, otherwise a reference is returned. Conversion to integers, doubles, Booleans, and strings are supported, as are vectors (i.e. arrays) and matrices (i.e. retangular arrays of arrays) of these types. The static type of the result, however, isAny
so using the methodevalXY
(whereX
isI
,D
,B
,S
, orR
andY
is0
,1
, or2
) may be more convenient (e.g. evalD0). -
def
evalD0(snippet: String): Double
Calls
eval(snippet,true)
and returns the result using getD0. -
def
evalD1(snippet: String): Array[Double]
Calls
eval(snippet,true)
and returns the result using getD1. -
def
evalD2(snippet: String): Array[Array[Double]]
Calls
eval(snippet,true)
and returns the result using getD2. -
def
evalI0(snippet: String): Int
Calls
eval(snippet,true)
and returns the result using getI0. -
def
evalI1(snippet: String): Array[Int]
Calls
eval(snippet,true)
and returns the result using getI1. -
def
evalI2(snippet: String): Array[Array[Int]]
Calls
eval(snippet,true)
and returns the result using getI2. -
def
evalL0(snippet: String): Boolean
Calls
eval(snippet,true)
and returns the result using getL0. -
def
evalL1(snippet: String): Array[Boolean]
Calls
eval(snippet,true)
and returns the result using getL1. -
def
evalL2(snippet: String): Array[Array[Boolean]]
Calls
eval(snippet,true)
and returns the result using getL2. -
def
evalR0(snippet: String): Byte
Calls
eval(snippet,true)
and returns the result using getR0. -
def
evalR1(snippet: String): Array[Byte]
Calls
eval(snippet,true)
and returns the result using getR1. -
def
evalR2(snippet: String): Array[Array[Byte]]
Calls
eval(snippet,true)
and returns the result using getR2. -
def
evalReference(snippet: String): PersistentReference
Calls
eval(snippet,true)
and returns the result using getReference. -
def
evalS0(snippet: String): String
Calls
eval(snippet,true)
and returns the result using getS0. -
def
evalS1(snippet: String): Array[String]
Calls
eval(snippet,true)
and returns the result using getS1. -
def
evalS2(snippet: String): Array[Array[String]]
Calls
eval(snippet,true)
and returns the result using getS2. -
def
exit(): Unit
Closes the interface to the R interpreter.
Closes the interface to the R interpreter.
Subsequent calls to the other methods will fail.
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
get(identifier: String, asReference: Boolean = false): (Any, String)
Returns the value of
identifier
in the R interpreter.Returns the value of
identifier
in the R interpreter. The static type of the result is(Any,String)
, where the first element is the value and the second is the runtime type.Conversion to integers, doubles, Booleans, and strings are supported, as are vectors (i.e. arrays) and matrices (i.e. retangular arrays of arrays) of these types. Using the method
getXY
(whereX
isI
,D
,B
, orS
andY
is0
,1
, or2
) may be more convenient (e.g. getD0). -
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
getD0(identifier: String): Double
Calls
get(identifier,false)
and converts the result to aDouble
. -
def
getD1(identifier: String): Array[Double]
Calls
get(identifier,false)
and converts the result to anArray[Double]
. -
def
getD2(identifier: String): Array[Array[Double]]
Calls
get(identifier,false)
and converts the result to anArray[Array[Double]]
. -
def
getI0(identifier: String): Int
Calls
get(identifier,false)
and converts the result to anInt
. -
def
getI1(identifier: String): Array[Int]
Calls
get(identifier,false)
and converts the result to anArray[Int]
. -
def
getI2(identifier: String): Array[Array[Int]]
Calls
get(identifier,false)
and converts the result to anArray[Array[Int]]
. -
def
getL0(identifier: String): Boolean
Calls
get(identifier,false)
and converts the result to aBoolean
. -
def
getL1(identifier: String): Array[Boolean]
Calls
get(identifier,false)
and converts the result to anArray[Boolean]
. -
def
getL2(identifier: String): Array[Array[Boolean]]
Calls
get(identifier,false)
and converts the result to anArray[Array[Boolean]]
. -
def
getR0(identifier: String): Byte
Calls
get(identifier,false)
and converts the result to aByte
. -
def
getR1(identifier: String): Array[Byte]
Calls
get(identifier,false)
and converts the result to anArray[Byte]
. -
def
getR2(identifier: String): Array[Array[Byte]]
Calls
get(identifier,false)
and converts the result to anArray[Array[Byte]]
. -
def
getReference(reference: EphemeralReference): PersistentReference
Converts an ephemeral R reference to a persistent R reference so that it can be accessed outside of the current environment.
-
def
getReference(identifier: String): PersistentReference
Obtains a persistent R reference to the named object so that it can be accessed outside of the current environment.
-
def
getS0(identifier: String): String
Calls
get(identifier,false)
and converts the result to aString
. -
def
getS1(identifier: String): Array[String]
Calls
get(identifier,false)
and converts the result to anArray[String]
. -
def
getS2(identifier: String): Array[Array[String]]
Calls
get(identifier,false)
and converts the result to anArray[Array[string]]
. -
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
invoke(functionName: String, args: Any*): Unit
Invokes an R function with arguments.
-
def
invoke(function: Reference, args: Any*): Unit
Invokes an R function with arguments.
-
def
invokeD0(functionName: String, args: Any*): Double
Invokes an R function with arguments and returns the result using getD0.
-
def
invokeD0(function: Reference, args: Any*): Double
Invokes an R function with arguments and returns the result using getD0.
-
def
invokeD1(functionName: String, args: Any*): Array[Double]
Invokes an R function with arguments and returns the result using getD1.
-
def
invokeD1(function: Reference, args: Any*): Array[Double]
Invokes an R function with arguments and returns the result using getD1.
-
def
invokeD2(functionName: String, args: Any*): Array[Array[Double]]
Invokes an R function with arguments and returns the result using getD2.
-
def
invokeD2(function: Reference, args: Any*): Array[Array[Double]]
Invokes an R function with arguments and returns the result using getD2.
-
def
invokeI0(functionName: String, args: Any*): Int
Invokes an R function with arguments and returns the result using getI0.
-
def
invokeI0(function: Reference, args: Any*): Int
Invokes an R function with arguments and returns the result using getI0.
-
def
invokeI1(functionName: String, args: Any*): Array[Int]
Invokes an R function with arguments and returns the result using getI1.
-
def
invokeI1(function: Reference, args: Any*): Array[Int]
Invokes an R function with arguments and returns the result using getI1.
-
def
invokeI2(functionName: String, args: Any*): Array[Array[Int]]
Invokes an R function with arguments and returns the result using getI2.
-
def
invokeI2(function: Reference, args: Any*): Array[Array[Int]]
Invokes an R function with arguments and returns the result using getI2.
-
def
invokeL0(functionName: String, args: Any*): Boolean
Invokes an R function with arguments and returns the result using getL0.
-
def
invokeL0(function: Reference, args: Any*): Boolean
Invokes an R function with arguments and returns the result using getL0.
-
def
invokeL1(functionName: String, args: Any*): Array[Boolean]
Invokes an R function with arguments and returns the result using getL1.
-
def
invokeL1(function: Reference, args: Any*): Array[Boolean]
Invokes an R function with arguments and returns the result using getL1.
-
def
invokeL2(functionName: String, args: Any*): Array[Array[Boolean]]
Invokes an R function with arguments and returns the result using getL2.
-
def
invokeL2(function: Reference, args: Any*): Array[Array[Boolean]]
Invokes an R function with arguments and returns the result using getL2.
-
def
invokeR0(functionName: String, args: Any*): Byte
Invokes an R function with arguments and returns the result using getR0.
-
def
invokeR0(function: Reference, args: Any*): Byte
Invokes an R function with arguments and returns the result using getR0.
-
def
invokeR1(functionName: String, args: Any*): Array[Byte]
Invokes an R function with arguments and returns the result using getR1.
-
def
invokeR1(function: Reference, args: Any*): Array[Byte]
Invokes an R function with arguments and returns the result using getR1.
-
def
invokeR2(functionName: String, args: Any*): Array[Array[Byte]]
Invokes an R function with arguments and returns the result using getR2.
-
def
invokeR2(function: Reference, args: Any*): Array[Array[Byte]]
Invokes an R function with arguments and returns the result using getR2.
-
def
invokeReference(functionName: String, args: Any*): PersistentReference
Invokes an R function with arguments and returns the result using getReference.
-
def
invokeReference(function: Reference, args: Any*): PersistentReference
Invokes an R function with arguments and returns the result using getReference.
-
def
invokeS0(functionName: String, args: Any*): String
Invokes an R function with arguments and returns the result using getS0.
-
def
invokeS0(function: Reference, args: Any*): String
Invokes an R function with arguments and returns the result using getS0.
-
def
invokeS1(functionName: String, args: Any*): Array[String]
Invokes an R function with arguments and returns the result using getS1.
-
def
invokeS1(function: Reference, args: Any*): Array[String]
Invokes an R function with arguments and returns the result using getS1.
-
def
invokeS2(functionName: String, args: Any*): Array[Array[String]]
Invokes an R function with arguments and returns the result using getS2.
-
def
invokeS2(function: Reference, args: Any*): Array[Array[String]]
Invokes an R function with arguments and returns the result using getS2.
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
ping(): Boolean
Pings the R interpreter.
Pings the R interpreter.
Calling this method periodically on an otherwise-idle client may prevent the operating system from closing the socket. Returns
true
if the ping is successful andfalse
otherwise. - val rowMajor: Boolean
-
def
selectDynamic(identifier: String): (Any, String)
A short-hand way to call get.
A short-hand way to call get.
R eval """ a <- numeric(10) for ( i in 2:length(a) ) { a[i] <- 0.5*a[i-1] + rnorm(1) } """ R.a
- val serializeOutput: Boolean
-
def
set(identifier: String, value: Any, index: String = "", singleBrackets: Boolean = true): Unit
Assigns
value
to a variableidentifier
in the R interpreter.Assigns
value
to a variableidentifier
in the R interpreter.Integers, doubles, Booleans, and strings are supported, as are vectors (i.e. arrays) and matrices (i.e. retangular arrays of arrays) of these types.
If
index != ""
, assigned into elements ofidentifier
are performed by using either single brackets (singleBrackets=true
) or double brackets (singleBrackets=false
).R.a = Array(5,6,4) R.eval("b <- matrix(NA,nrow=3,ncol=2)") for ( i <- 0 until 3 ) { R.set("b",Array(2*i,2*i+1),s"${i+1},") } R.b R.eval("myList <- list()") R.set("myList",Array("David","Grace","Susan"),"'names'",false) R.set("myList",Array(5,4,5),"'counts'",false) R.eval("print(myList)")
-
def
set(identifier: String, value: Any): Unit
Equivalent to calling
set(identifier, value, "", true)
. -
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
updateDynamic(identifier: String)(value: Any): Unit
A short-hand way to call
set(identifier,value)
A short-hand way to call
set(identifier,value)
R.b = Array.fill(10) { scala.math.random }
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )