[R] type of list elements in .Call

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Jan 31 09:05:10 CET 2005


Please ask programming-related questions on the R-devel list -- see the 
advice in the posting guide.

On Mon, 31 Jan 2005, Faheem Mitha wrote:

>
> 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.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list