Class/Object

org.ddahl.rscala

RClient

Related Docs: object RClient | package rscala

Permalink

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]]
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
Visibility
  1. Public
  2. All

Value Members

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

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

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

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def cached(identifier: String): Any

    Permalink

    For rscala developers only: Returns a value previously cached for the R interpreter.

  6. def clone(): AnyRef

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

    Permalink

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

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  10. def eval(snippet: String): Unit

    Permalink

    Calls eval(snippet,true).

  11. def eval(snippet: String, evalOnly: Boolean, asReference: Boolean): (Any, String)

    Permalink

    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 returned. The result is converted if asReference is false 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, is Any so using the method evalXY (where X is I, D, B, S, or R and Y is 0, 1, or 2) may be more convenient (e.g. evalD0).

  12. def evalD0(snippet: String): Double

    Permalink

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

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

    Permalink

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

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

    Permalink

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

  15. def evalI0(snippet: String): Int

    Permalink

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

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

    Permalink

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

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

    Permalink

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

  18. def evalL0(snippet: String): Boolean

    Permalink

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

  19. def evalL1(snippet: String): Array[Boolean]

    Permalink

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

  20. def evalL2(snippet: String): Array[Array[Boolean]]

    Permalink

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

  21. def evalR0(snippet: String): Byte

    Permalink

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

  22. def evalR1(snippet: String): Array[Byte]

    Permalink

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

  23. def evalR2(snippet: String): Array[Array[Byte]]

    Permalink

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

  24. def evalReference(snippet: String): PersistentReference

    Permalink

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

  25. def evalS0(snippet: String): String

    Permalink

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

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

    Permalink

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

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

    Permalink

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

  28. def exit(): Unit

    Permalink

    Closes the interface to the R interpreter.

    Closes the interface to the R interpreter.

    Subsequent calls to the other methods will fail.

  29. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  30. def get(identifier: String, asReference: Boolean = false): (Any, String)

    Permalink

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

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

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

    Permalink

    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.

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

    Permalink

    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.

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

    Permalink

    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.

  35. def getI0(identifier: String): Int

    Permalink

    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.

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

    Permalink

    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.

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

    Permalink

    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.

  38. def getL0(identifier: String): Boolean

    Permalink

    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.

  39. def getL1(identifier: String): Array[Boolean]

    Permalink

    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.

  40. def getL2(identifier: String): Array[Array[Boolean]]

    Permalink

    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.

  41. def getR0(identifier: String): Byte

    Permalink

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

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

    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 getR1(identifier: String): Array[Byte]

    Permalink

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

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

    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.

  43. def getR2(identifier: String): Array[Array[Byte]]

    Permalink

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

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

    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.

  44. def getReference(reference: EphemeralReference): PersistentReference

    Permalink

    Converts an ephemeral R reference to a persistent R reference so that it can be accessed outside of the current environment.

  45. def getReference(identifier: String): PersistentReference

    Permalink

    Obtains a persistent R reference to the named object so that it can be accessed outside of the current environment.

  46. def getS0(identifier: String): String

    Permalink

    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.

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

    Permalink

    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.

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

    Permalink

    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.

  49. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  50. def invoke(functionName: String, args: Any*): Unit

    Permalink

    Invokes an R function with arguments.

  51. def invoke(function: Reference, args: Any*): Unit

    Permalink

    Invokes an R function with arguments.

  52. def invokeD0(functionName: String, args: Any*): Double

    Permalink

    Invokes an R function with arguments and returns the result using getD0.

  53. def invokeD0(function: Reference, args: Any*): Double

    Permalink

    Invokes an R function with arguments and returns the result using getD0.

  54. def invokeD1(functionName: String, args: Any*): Array[Double]

    Permalink

    Invokes an R function with arguments and returns the result using getD1.

  55. def invokeD1(function: Reference, args: Any*): Array[Double]

    Permalink

    Invokes an R function with arguments and returns the result using getD1.

  56. def invokeD2(functionName: String, args: Any*): Array[Array[Double]]

    Permalink

    Invokes an R function with arguments and returns the result using getD2.

  57. def invokeD2(function: Reference, args: Any*): Array[Array[Double]]

    Permalink

    Invokes an R function with arguments and returns the result using getD2.

  58. def invokeI0(functionName: String, args: Any*): Int

    Permalink

    Invokes an R function with arguments and returns the result using getI0.

  59. def invokeI0(function: Reference, args: Any*): Int

    Permalink

    Invokes an R function with arguments and returns the result using getI0.

  60. def invokeI1(functionName: String, args: Any*): Array[Int]

    Permalink

    Invokes an R function with arguments and returns the result using getI1.

  61. def invokeI1(function: Reference, args: Any*): Array[Int]

    Permalink

    Invokes an R function with arguments and returns the result using getI1.

  62. def invokeI2(functionName: String, args: Any*): Array[Array[Int]]

    Permalink

    Invokes an R function with arguments and returns the result using getI2.

  63. def invokeI2(function: Reference, args: Any*): Array[Array[Int]]

    Permalink

    Invokes an R function with arguments and returns the result using getI2.

  64. def invokeL0(functionName: String, args: Any*): Boolean

    Permalink

    Invokes an R function with arguments and returns the result using getL0.

  65. def invokeL0(function: Reference, args: Any*): Boolean

    Permalink

    Invokes an R function with arguments and returns the result using getL0.

  66. def invokeL1(functionName: String, args: Any*): Array[Boolean]

    Permalink

    Invokes an R function with arguments and returns the result using getL1.

  67. def invokeL1(function: Reference, args: Any*): Array[Boolean]

    Permalink

    Invokes an R function with arguments and returns the result using getL1.

  68. def invokeL2(functionName: String, args: Any*): Array[Array[Boolean]]

    Permalink

    Invokes an R function with arguments and returns the result using getL2.

  69. def invokeL2(function: Reference, args: Any*): Array[Array[Boolean]]

    Permalink

    Invokes an R function with arguments and returns the result using getL2.

  70. def invokeR0(functionName: String, args: Any*): Byte

    Permalink

    Invokes an R function with arguments and returns the result using getR0.

  71. def invokeR0(function: Reference, args: Any*): Byte

    Permalink

    Invokes an R function with arguments and returns the result using getR0.

  72. def invokeR1(functionName: String, args: Any*): Array[Byte]

    Permalink

    Invokes an R function with arguments and returns the result using getR1.

  73. def invokeR1(function: Reference, args: Any*): Array[Byte]

    Permalink

    Invokes an R function with arguments and returns the result using getR1.

  74. def invokeR2(functionName: String, args: Any*): Array[Array[Byte]]

    Permalink

    Invokes an R function with arguments and returns the result using getR2.

  75. def invokeR2(function: Reference, args: Any*): Array[Array[Byte]]

    Permalink

    Invokes an R function with arguments and returns the result using getR2.

  76. def invokeReference(functionName: String, args: Any*): PersistentReference

    Permalink

    Invokes an R function with arguments and returns the result using getReference.

  77. def invokeReference(function: Reference, args: Any*): PersistentReference

    Permalink

    Invokes an R function with arguments and returns the result using getReference.

  78. def invokeS0(functionName: String, args: Any*): String

    Permalink

    Invokes an R function with arguments and returns the result using getS0.

  79. def invokeS0(function: Reference, args: Any*): String

    Permalink

    Invokes an R function with arguments and returns the result using getS0.

  80. def invokeS1(functionName: String, args: Any*): Array[String]

    Permalink

    Invokes an R function with arguments and returns the result using getS1.

  81. def invokeS1(function: Reference, args: Any*): Array[String]

    Permalink

    Invokes an R function with arguments and returns the result using getS1.

  82. def invokeS2(functionName: String, args: Any*): Array[Array[String]]

    Permalink

    Invokes an R function with arguments and returns the result using getS2.

  83. def invokeS2(function: Reference, args: Any*): Array[Array[String]]

    Permalink

    Invokes an R function with arguments and returns the result using getS2.

  84. final def isInstanceOf[T0]: Boolean

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

    Permalink
    Definition Classes
    AnyRef
  86. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  87. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  88. def ping(): Boolean

    Permalink

    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 and false otherwise.

  89. val rowMajor: Boolean

    Permalink
  90. def selectDynamic(identifier: String): (Any, String)

    Permalink

    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
  91. val serializeOutput: Boolean

    Permalink
  92. def set(identifier: String, value: Any, index: String = "", singleBrackets: Boolean = true): Unit

    Permalink

    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)")
  93. def set(identifier: String, value: Any): Unit

    Permalink

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

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

    Permalink
    Definition Classes
    AnyRef
  95. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  96. def updateDynamic(identifier: String)(value: Any): Unit

    Permalink

    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 }
  97. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Dynamic

Inherited from AnyRef

Inherited from Any

Ungrouped