Interface RValue

All Known Implementing Classes:
RValue.Int, RValue.List, RValue.Logical, RValue.Null, RValue.Num, RValue.Other, RValue.Raw, RValue.Str

An R object as Java data (a copy). Read with doubles(), ints(), strings(), booleans(), bytes(), firstDouble(), firstString(), elements(), matrix() and create with RValue.of(...), listOf(...), dataFrame(...), factor(...).

The types as records: The vector types of R map to one record each; the attributes names, dim, dimnames, class, levels and row.names are kept (other attributes are not transferred).

NA: R's own values are kept (integer and logical: NA_INTEGER, double: the NA bit pattern, see isNA(double), character: null).

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final record 
    An integer vector (also a factor: the codes with the attribute "levels").
    static final record 
    A list (also a data frame: class "data.frame" with names and row.names).
    static final record 
    A logical vector: 1 (TRUE), 0 (FALSE), NA_INTEGER (NA).
    static final record 
    NULL.
    static final record 
    A numeric (double) vector, a matrix with the attribute "dim".
    static final record 
    An object which is not transferred (e.g., a function or an environment): only its type.
    static final record 
    A raw vector.
    static final record 
    A character vector (null is NA).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    NA of integer and logical vectors (as in R).
    static final double
    NA_real_ of R (a NaN with a payload, distinct from NaN).
    static final long
    The bit pattern of NA_real_ in R.
    static final RValue
    NULL of R.
  • Method Summary

    Modifier and Type
    Method
    Description
    default RValue
    The attribute or null.
    The attributes (names, dim, dimnames, class, levels, row.names), never null.
    static Map<String,RValue>
    attributes(Object... nameValuePairs)
    Attributes with names and values (e.g., attributes("names", names)).
    default boolean[]
    The values as booleans: logical values (NA: false), numbers (not 0: true).
    default byte[]
    The bytes of a raw vector.
    static RValue
    A data frame: the columns (vectors of the same length) by name.
    default int[]
    dim()
    The dimensions (the "dim" attribute) or null.
    default double[]
    The values as numbers: numeric, integer and logical vectors (NA: NA_REAL), character vectors are parsed (not a number: NA_REAL).
    default RValue
    element(int index)
    An element of a list (from 0).
    default RValue
    An element of a list by name, or null.
    default List<RValue>
    The elements of a list (also the columns of a data frame).
    static RValue
    factor(String... labels)
    A factor: the labels (null: NA), the levels sorted as in R.
    default double
    The first number (see doubles()).
    default int
    The first integer (see ints()).
    default String
    The first text (see strings()).
    default boolean
    Returns true if the "class" attribute contains the class.
    default int[]
    The values as integers: integer and logical vectors, numbers are truncated (NA, NaN: NA_INTEGER).
    default boolean
    A character vector.
    default boolean
     
    default boolean
     
    default boolean
    A list (also a data frame).
    default boolean
     
    default boolean
    A matrix (two dimensions).
    static boolean
    isNA(double v)
    Returns true if a double is R's NA (not any NaN).
    default boolean
     
    default boolean
    Numbers: a numeric or an integer vector (not a factor).
    default boolean
     
    default boolean
    True if the first value is TRUE (a logical vector, e.g., of is.numeric(x)).
    int
    The number of elements (0 for NULL).
    static RValue
    listOf(RValue... elements)
    A list without names.
    static RValue
    listOf(Map<String,RValue> elements)
    A list with names (in the order of the map).
    default double[][]
    A matrix as rows: [row][column] (numbers with two dimensions).
    default String[]
    The names (the "names" attribute) or null.
    static RValue
    of(boolean... values)
    A logical vector.
    static RValue
    of(byte... values)
    A raw vector.
    static RValue
    of(double... values)
    A numeric vector.
    static RValue
    of(int... values)
    An integer vector.
    static RValue
    of(String... values)
    A character vector (null: NA).
    default String[]
    The values as text: a character vector (NA: null), the labels of a factor, numbers and logical values as text (NA: "NA").
    default String
    The type of R, e.g., "double", "character", "list" (for messages).
    default RValue
    with(String attribute, RValue value)
    This value with one attribute more (or replaced; null removes it).
    default RValue
    withDim(int... dim)
    This value as a matrix or an array with the dimensions.
    default RValue
    withNames(String... names)
    This value with names.
  • Field Details

    • NA_INTEGER

      static final int NA_INTEGER
      NA of integer and logical vectors (as in R).
      See Also:
    • NA_REAL_BITS

      static final long NA_REAL_BITS
      The bit pattern of NA_real_ in R.
      See Also:
    • NA_REAL

      static final double NA_REAL
      NA_real_ of R (a NaN with a payload, distinct from NaN).
    • NULL

      static final RValue NULL
      NULL of R.
  • Method Details

    • isNA

      static boolean isNA(double v)
      Returns true if a double is R's NA (not any NaN).
    • attributes

      Map<String,RValue> attributes()
      The attributes (names, dim, dimnames, class, levels, row.names), never null.
    • length

      int length()
      The number of elements (0 for NULL).
    • attribute

      default RValue attribute(String name)
      The attribute or null.
    • names

      default String[] names()
      The names (the "names" attribute) or null.
    • dim

      default int[] dim()
      The dimensions (the "dim" attribute) or null.
    • inherits

      default boolean inherits(String cls)
      Returns true if the "class" attribute contains the class.
    • of

      static RValue of(double... values)
      A numeric vector.
    • of

      static RValue of(int... values)
      An integer vector.
    • of

      static RValue of(String... values)
      A character vector (null: NA).
    • of

      static RValue of(boolean... values)
      A logical vector.
    • of

      static RValue of(byte... values)
      A raw vector.
    • listOf

      static RValue listOf(RValue... elements)
      A list without names.
    • listOf

      static RValue listOf(Map<String,RValue> elements)
      A list with names (in the order of the map).
    • dataFrame

      static RValue dataFrame(Map<String,RValue> columns)
      A data frame: the columns (vectors of the same length) by name.
    • factor

      static RValue factor(String... labels)
      A factor: the labels (null: NA), the levels sorted as in R.
    • with

      default RValue with(String attribute, RValue value)
      This value with one attribute more (or replaced; null removes it).
    • withNames

      default RValue withNames(String... names)
      This value with names.
    • withDim

      default RValue withDim(int... dim)
      This value as a matrix or an array with the dimensions.
    • isNull

      default boolean isNull()
    • isNumeric

      default boolean isNumeric()
      Numbers: a numeric or an integer vector (not a factor).
    • isCharacter

      default boolean isCharacter()
      A character vector.
    • isLogical

      default boolean isLogical()
    • isRaw

      default boolean isRaw()
    • isList

      default boolean isList()
      A list (also a data frame).
    • isFactor

      default boolean isFactor()
    • isDataFrame

      default boolean isDataFrame()
    • isMatrix

      default boolean isMatrix()
      A matrix (two dimensions).
    • typeName

      default String typeName()
      The type of R, e.g., "double", "character", "list" (for messages).
    • doubles

      default double[] doubles()
      The values as numbers: numeric, integer and logical vectors (NA: NA_REAL), character vectors are parsed (not a number: NA_REAL).
    • ints

      default int[] ints()
      The values as integers: integer and logical vectors, numbers are truncated (NA, NaN: NA_INTEGER).
    • strings

      default String[] strings()
      The values as text: a character vector (NA: null), the labels of a factor, numbers and logical values as text (NA: "NA").
    • booleans

      default boolean[] booleans()
      The values as booleans: logical values (NA: false), numbers (not 0: true).
    • bytes

      default byte[] bytes()
      The bytes of a raw vector.
    • firstDouble

      default double firstDouble()
      The first number (see doubles()).
    • firstInt

      default int firstInt()
      The first integer (see ints()).
    • firstString

      default String firstString()
      The first text (see strings()).
    • isTrue

      default boolean isTrue()
      True if the first value is TRUE (a logical vector, e.g., of is.numeric(x)).
    • elements

      default List<RValue> elements()
      The elements of a list (also the columns of a data frame).
    • element

      default RValue element(int index)
      An element of a list (from 0).
    • element

      default RValue element(String name)
      An element of a list by name, or null.
    • matrix

      default double[][] matrix()
      A matrix as rows: [row][column] (numbers with two dimensions).
    • attributes

      static Map<String,RValue> attributes(Object... nameValuePairs)
      Attributes with names and values (e.g., attributes("names", names)).