[Rd] type of list elements in .Call

From: Faheem Mitha <faheem_at_email.unc.edu>
Date: Tue 01 Feb 2005 - 01:57:37 EST

[Forwarding to r-devel.]

Dear People,

Here is something I do not understand. Consider



foo.cc
#include <iostream>
#include <R.h>
#include <Rinternals.h>

using std::cout;
using std::endl;

extern "C"
{

   SEXP printlst(SEXP lst);
}

SEXP printlst(SEXP lst)
{

   for(int i=0; i<length(lst); i++)

     for(int j=0; j<length(VECTOR_ELT(lst, i)); j++)
       cout << INTEGER(VECTOR_ELT(lst, i))[j] << endl;
   return lst;
}

> dyn.load("foo.so")
> .Call("printlst", list(c(1,2),c(3,4)))
0
1072693248
0
1074266112
[[1]]
[1] 1 2

[[2]]
[1] 3 4

If I replace INTEGER by REAL I get

> dyn.load("foo.so")
> .Call("printlst", list(c(1,2),c(3,4)))
1
2
3
4
[[1]]
[1] 1 2

[[2]]
[1] 3 4

as I would expect. I thought that if the vectors in the list could be regarded as integer vectors, they would be coerced appropriately, but apparently not. Is there any way I can tell R to regard them as integer vectors?

Thanks.                                                    Faheem.

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Feb 01 01:11:42 2005

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:02:43 EST