org.ddahl.rscala

RClient

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 JVM-based 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.11, for example, use rscala::rscalaJar("2.11").

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 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]]
Linear Supertypes
Dynamic, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. RClient
  2. Dynamic
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. def debug: Boolean

    For rscala developers only: Returns TRUE if debugging output is enabled.

  9. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  11. def eval(snippet: String, evalOnly: Boolean = true): Any

    Evaluates snippet in the R interpreter.

    Evaluates snippet in the R interpreter.

    Returns null if evalOnly. If !evalOnly, the last result of the R expression is converted if possible. 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, is Any so using the method evalXY (where X is I, D, B, or S and Y is 0, 1, or 2) may be more convenient (e.g. evalD0).

  12. def evalB0(snippet: String): Boolean

    Calls eval(snippet,true) and returns the result using getB0.

  13. def evalB1(snippet: String): Array[Boolean]

    Calls eval(snippet,true) and returns the result using getB1.

  14. def evalB2(snippet: String): Array[Array[Boolean]]

    Calls eval(snippet,true) and returns the result using getB2.

  15. def evalD0(snippet: String): Double

    Calls eval(snippet,true) and returns the result using getD0.

  16. def evalD1(snippet: String): Array[Double]

    Calls eval(snippet,true) and returns the result using getD1.

  17. def evalD2(snippet: String): Array[Array[Double]]

    Calls eval(snippet,true) and returns the result using getD2.

  18. def evalI0(snippet: String): Int

    Calls eval(snippet,true) and returns the result using getI0.

  19. def evalI1(snippet: String): Array[Int]

    Calls eval(snippet,true) and returns the result using getI1.

  20. def evalI2(snippet: String): Array[Array[Int]]

    Calls eval(snippet,true) and returns the result using getI2.

  21. def evalR(snippet: String): RObject

    Calls eval(snippet,true) and returns the result using getR.

  22. def evalS0(snippet: String): String

    Calls eval(snippet,true) and returns the result using getS0.

  23. def evalS1(snippet: String): Array[String]

    Calls eval(snippet,true) and returns the result using getS1.

  24. def evalS2(snippet: String): Array[Array[String]]

    Calls eval(snippet,true) and returns the result using getS2.

  25. 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.

  26. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  27. def gc(): Unit

    Reclaims memory associated with all R references, including any instances of RObject that are still in memory.

  28. 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.

    If asReference=false, 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 (where X is I, D, B, or S and Y is 0, 1, or 2) may be more convenient (e.g. getD0).

    If asReference=true, the value is merely wrapped using RObject and objects of any type are supported. Using the method getR may be more convenient.

  29. def getB0(identifier: String): Boolean

    Calls get(identifier,false) and converts the result to a Boolean.

    Calls get(identifier,false) and converts the result to a Boolean.

    Integers, doubles, Booleans, and strings are supported. Vectors (i.e. arrays) of these types are also supported by converting the first element. Matrices (i.e. rectangular arrays of arrays) are not supported.

  30. def getB1(identifier: String): Array[Boolean]

    Calls get(identifier,false) and converts the result to an Array[Boolean].

    Calls get(identifier,false) and converts the result to an Array[Boolean].

    Integers, doubles, Booleans, and strings are supported. Vectors (i.e. arrays) of these types are also supported by converting the first element. Matrices (i.e. rectangular arrays of arrays) are not supported.

  31. def getB2(identifier: String): Array[Array[Boolean]]

    Calls get(identifier,false) and converts the result to an Array[Array[Boolean]].

    Calls get(identifier,false) and converts the result to an Array[Array[Boolean]].

    Matrices (i.e. rectangular arrays of arrays) of integers, doubles, Booleans, and strings are supported. Integers, doubles, Booleans, and strings themselves are not supported. Vectors (i.e. arrays) of these types are also not supported.

  32. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  33. def getD0(identifier: String): Double

    Calls get(identifier,false) and converts the result to a Double.

    Calls get(identifier,false) and converts the result to a Double.

    Integers, doubles, Booleans, and strings are supported. Vectors (i.e. arrays) of these types are also supported by converting the first element. Matrices (i.e. rectangular arrays of arrays) are not supported.

  34. def getD1(identifier: String): Array[Double]

    Calls get(identifier,false) and converts the result to an Array[Double].

    Calls get(identifier,false) and converts the result to an Array[Double].

    Integers, doubles, Booleans, and strings are supported. Vectors (i.e. arrays) of these types are also supported by converting the first element. Matrices (i.e. rectangular arrays of arrays) are not supported.

  35. def getD2(identifier: String): Array[Array[Double]]

    Calls get(identifier,false) and converts the result to an Array[Array[Double]].

    Calls get(identifier,false) and converts the result to an Array[Array[Double]].

    Matrices (i.e. rectangular arrays of arrays) of integers, doubles, Booleans, and strings are supported. Integers, doubles, Booleans, and strings themselves are not supported. Vectors (i.e. arrays) of these types are also not supported.

  36. def getI0(identifier: String): Int

    Calls get(identifier,false) and converts the result to an Int.

    Calls get(identifier,false) and converts the result to an Int.

    Integers, doubles, Booleans, and strings are supported. Vectors (i.e. arrays) of these types are also supported by converting the first element. Matrices (i.e. rectangular arrays of arrays) are not supported.

  37. def getI1(identifier: String): Array[Int]

    Calls get(identifier,false) and converts the result to an Array[Int].

    Calls get(identifier,false) and converts the result to an Array[Int].

    Integers, doubles, Booleans, and strings are supported. Vectors (i.e. arrays) of these types are also supported by converting the first element. Matrices (i.e. rectangular arrays of arrays) are not supported.

  38. def getI2(identifier: String): Array[Array[Int]]

    Calls get(identifier,false) and converts the result to an Array[Array[Int]].

    Calls get(identifier,false) and converts the result to an Array[Array[Int]].

    Matrices (i.e. rectangular arrays of arrays) of integers, doubles, Booleans, and strings are supported. Integers, doubles, Booleans, and strings themselves are not supported. Vectors (i.e. arrays) of these types are also not supported.

  39. def getR(identifier: String): RObject

    Calls get(identifier,true) and converts the result to an RObject.

    Calls get(identifier,true) and converts the result to an RObject.

    The value is merely wrapped using RObject and objects of any type are supported.

  40. def getS0(identifier: String): String

    Calls get(identifier,false) and converts the result to a string.

    Calls get(identifier,false) and converts the result to a string.

    Integers, doubles, Booleans, and strings are supported. Vectors (i.e. arrays) of these types are also supported by converting the first element. Matrices (i.e. rectangular arrays of arrays) are not supported.

  41. def getS1(identifier: String): Array[String]

    Calls get(identifier,false) and converts the result to an Array[string].

    Calls get(identifier,false) and converts the result to an Array[string].

    Integers, doubles, Booleans, and strings are supported. Vectors (i.e. arrays) of these types are also supported by converting the first element. Matrices (i.e. rectangular arrays of arrays) are not supported.

  42. def getS2(identifier: String): Array[Array[String]]

    Calls get(identifier,false) and converts the result to an Array[Array[string]].

    Calls get(identifier,false) and converts the result to an Array[Array[string]].

    Matrices (i.e. rectangular arrays of arrays) of integers, doubles, Booleans, and strings are supported. Integers, doubles, Booleans, and strings themselves are not supported. Vectors (i.e. arrays) of these types are also not supported.

  43. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  44. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  45. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  46. final def notify(): Unit

    Definition Classes
    AnyRef
  47. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  48. 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
  49. def set(identifier: String, value: Any, index: String = "", singleBrackets: Boolean = true): Unit

    Assigns value to a variable identifier in the R interpreter.

    Assigns value to a variable identifier 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 of identifier 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)")
  50. def set(identifier: String, value: Any): Unit

    Equivalent to calling set(identifier, value, "", true).

  51. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  52. def toString(): String

    Definition Classes
    AnyRef → Any
  53. 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 }
  54. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  55. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  56. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Dynamic

Inherited from AnyRef

Inherited from Any

Ungrouped