-
Notifications
You must be signed in to change notification settings - Fork 27
to_ruby worflow
Objective: Provides rules to transform R object (Rserve::REXP subclasses) on appropriate Ruby objects
Any REXP object should have a to_ruby method, which enable fast retrieval of information. This object should be assigned to R variables using Rserve::Connection.assign without (much) loss of information.
To allow this, the following criteria will be used with REXP subclasses:
- Integer with one element: Fixnum (implemented)
- Integer with two or more elements: Array of Fixnum (implemented)
- Double with one element: Float (implemented)
- Double with two or more elements: Array of Floats (implemented)
- Double with attribute dim with 2 values: standard library Matrix (implemented)
- Double with attribute dim with 3 or more values: Nested arrays of Matrixes (implemented)
- Logical with one element: boolean (TrueClass or FalseClass) (implemented)
- Logical with two or more elements: Array of booleans (implemented)
- String with one element: String (implemented)
- String with two or more elements: Array of String (implemented)
- List: Array extended with module Rserve::WithNames (implemented)
- List with class ‘data.frame’: Array extended with module Rserve::WithNames. Attribute ‘row.names’ should have correct assignment for enumerations (implemented)
- Data
- NA and NaN will be replaced with nil on every case (implemented).
- Every object with attributes will be extended with module Rserve::WithAttributes (implemented)
- Every object with names (like List) will be extended with module Rserve::WithNames (implemented). The attribute ‘names’ will be always an array.
Racionality for List:
The first option for named List is Hash, of course. Problem arises when not every element is named; you could create numerical keys to access this elements, but this implies do some trickery to obtain numerical values of named elements. So, better is maintain untouched the positional reference as an Array and overload only :[] to allows numerical (0 and 1-based using syntactic sugar) and named retrieval of data
So
a [ 0] => first element
a[ [ 1]] => first element (detect an array!)
a[ ‘first’] => first element (named)