From faheem at email.unc.edu  Mon Jan 31 15:57:37 2005
From: faheem at email.unc.edu (Faheem Mitha)
Date: Mon Jan 31 15:57:51 2005
Subject: [Rd] type of list elements in .Call
Message-ID: <Pine.LNX.4.61.0501310953100.10677@Chrestomanci>


[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.


[Rd] type of list elements in .Call
Faheem Mitha