I have a list,> rb$t [1] "tree" $x [1] 0 $cut [1] 0.8 $l [1] 0 0 and pass it through .C("fn",rb) to void fn(ev) int **ev; { double cut; cut = *(double *)ev[2][0]; printf("%8.5f\n",cut); } in S-4, it produces 0.8, as I want. But R (version 1.3.1, linux) produces a segmentation fault. Is it possible to access list elements in R? The manual seems to suggest writing .Call interfaces, which I want to avoid. Thanks, Catherine. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Tue, 11 Dec 2001, Catherine Loader wrote:> I have a list, > > > rb > $t > [1] "tree" > > $x > [1] 0 > > $cut > [1] 0.8 > > $l > [1] 0 0 > > and pass it through .C("fn",rb) to > > void fn(ev) > int **ev; > { double cut; > cut = *(double *)ev[2][0]; > printf("%8.5f\n",cut); > } > > in S-4, it produces 0.8, as I want. > But R (version 1.3.1, linux) produces a segmentation fault. > Is it possible to access list elements in R? The manual seems > to suggest writing .Call interfaces, which I want to avoid.Yes, but it would be no easier than using .Call. ?Foreign says Lists are passed as C arrays of `SEXP' and can be declared as `void *' or `SEXP *'. so you do need to mess with SEXPs. Something like (minimally tested) #include <R.h> #include <Rinternals.h> void fn(SEXP *ev) { SEXP cut = ev[2]; printf("%8.5f\n", REAL(cut)[0]); } Note that using printf is not portable, but presumably this was just a test. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "CL" == Catherine Loader <catherine at research.bell-labs.com> writes:CL> I have a list, >> rb CL> $t [1] "tree" CL> $x [1] 0 CL> $cut [1] 0.8 CL> $l [1] 0 0 CL> and pass it through .C("fn",rb) to CL> void fn(ev) CL> int **ev; CL> { double cut; CL> cut = *(double *)ev[2][0]; CL> printf("%8.5f\n",cut); CL> } CL> in S-4, it produces 0.8, as I want. which is astonishing, and AFAIK not at all to be relied on. CL> But R (version 1.3.1, linux) produces a segmentation fault. CL> Is it possible to access list elements in R? yes, via .Call() CL> The manual seems to suggest writing .Call CL> interfaces, which I want to avoid. no way (to avoid this)! It's also the (only?) way publicized for S4 (based versions of S-PLUS). Regards, Martin -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._