single element list in R

asked 2017-05-26 18:12:16 +0200

mlanting gravatar image

updated 2017-07-14 00:07:36 +0200

vdelecroix gravatar image

I'm using R to filter a large dataset to a dictionary of lists of values, and using those lists in Sage/Python to make plots. The data is a bunch of measurements between nodes, and I'm trying to automate filtering the data into a bunch of lists for the different permutations nodes. However, if a node pair only consists of one measurement, R is returning it as a float instead of a single element list (this is with the r('measurements$node1$node2$value')._sage_() interface). This is causing code later on to choke. I'd like to avoid a bunch of ugly type-checking on the return values from R if possible.

Is there a way to force R to return a single element list instead of a float some other single-value numeric type?

edit retag flag offensive close merge delete


It is hard to reproduce the problem in both R and sage. We miss for instance measurementsnode1node2. If this can be hard coded to mock the situation in R, we have a better grip on the problem. And there is hard to see where the code is getting the (sage or R?) chain. My problems were some years ago of the shape

sage: X = r( 'c( c(111,256,2017), 77, c(4) )' )
sage: X
[1]  111  256 2017   77    4
sage: type(X)
<class 'sage.interfaces.r.RElement'>
sage: len(X)
sage: X[0]
sage: X[1]
[1] 111
sage: X[2]
[1] 256
sage: X[3]
[1] 2017
sage: X[4]
[1] 77
sage: X[5]
[1] 4
sage: X[6]
[1] NA

(It's hard to recover the initial structure of R, and to use R data.) Please give some more details, if possible.

dan_fulea gravatar imagedan_fulea ( 2017-05-30 19:54:32 +0200 )edit