ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 30 May 2017 19:54:32 +0200single element list in Rhttps://ask.sagemath.org/question/37704/single-element-list-in-r/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?Fri, 26 May 2017 18:12:16 +0200https://ask.sagemath.org/question/37704/single-element-list-in-r/Comment by dan_fulea for <p>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 <code>r('measurements$node1$node2$value')._sage_()</code> 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.</p>
<p>Is there a way to force R to return a single element list instead of a float some other single-value numeric type?</p>
https://ask.sagemath.org/question/37704/single-element-list-in-r/?comment=37742#post-id-37742It 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)
5
sage: X[0]
numeric(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.Tue, 30 May 2017 19:54:32 +0200https://ask.sagemath.org/question/37704/single-element-list-in-r/?comment=37742#post-id-37742