I'm working with the rserve-client gem, which allows a Ruby script to communicate with R via TCP/IP. Part of that involves serializing Ruby objects to send over the wire, and transparently converting the results that come back into Ruby.
However, the array objects returned have a strange notation associated with them I've never seen before, when an R table is translated back into Ruby.
For example an R table with a named id column and 3 values returns:
res
=> [|WN|"id"=[1,
2,
3]
res.to_s
=> "[id=[1, 2, 3]]"
res.class
=> Array
res.inspect
=> "#<Array:70227288405140 [id=[1, 2, 3]]>"
res.class.ancestors == Array.ancestors
=> true
=> [[1,
2,
3]]
Any idea what this is? Ideally I would like to convert it to a hash to use ID...to_hash doesn't get it. .to_a results in:
The answer is in the rserve gem source.
Array
has been decorated with a newpretty_print
method:https://github.com/clbustos/Rserve-Ruby-client/blob/a4edabd5c742f08a9b2394ce255707219aafd7df/lib/rserve/withnames.rb#L16