[Rd] send a list from R to C

Jörn Schulz noah78 at web.de
Tue Jul 18 14:20:18 CEST 2006

Hello at all !

What is the correct form to give a list form R (e.g. list(c(-1,1),
"TestFile") ) to C. I have no problems, if I don't use character and I have
also no problems to give a character vector form R to C. But,  if I combine
real and strings in a list then I don't know the correct syntax.

I try it with following (an example):

SEXP writeFile(SEXP headerR){
Image *SaveImage;

PROTECT(headerR = AS_VECTOR(headerR));
SaveImage->Xmin = (float) REAL(VECTOR_ELT(headerR, 0))[0];
SaveImage->Ymin = (float) REAL(VECTOR_ELT(headerR, 0))[1];
strcpy(SaveImage->Description, CHAR(STRING_ELT(headerR, 1)));


typedef struct {
  float Xmin;
  float Ymin;
  char Description[80];
  } Image;

But with this form the characters are doesn't correct (in this case
Description). Perhaps a problem is that I protect the list with AS_VECTOR.
Or is it not possible to comitted a list from R to C that contain numeric
values and characters ?
View this message in context: http://www.nabble.com/send-a-list-from-R-to-C-tf1960161.html#a5377049
Sent from the R devel forum at Nabble.com.

More information about the R-devel mailing list