[R] type of list elements in .Call
Faheem Mitha
faheem at email.unc.edu
Mon Jan 31 06:00:22 CET 2005
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, but apparently not. Is there
any way I can tell R to regard them as integer vectors?
Thanks. Faheem.
More information about the R-help
mailing list