[Rd] C Interface to R? New question

Alexander Schinner alexander_schinner at genua.de
Thu Apr 28 16:01:31 CEST 2005


Hi,

thanks for your help by pointing to the correct documentation and 
tests/Embedding from 2.1.0. Using this information, I could realize most of 
the work, I wanted to accomplish. Still, one problem is remaining.

In principle, I whould like to do

> dim(matrix) 
[1] 100   3
> matrix[,3] 
 [1] 201 202 203 ......

But how do I use the [ function from C? From the manual, I learned, that the 
missing value before the "," is an empty list, but how to make one? 

I tried something like

  R_result = getListElement(R_stl_y, "time.series");

  PROTECT(Rc_bracket = allocVector(LANGSXP, 4));
  SETCAR(Rc_bracket, Rf_findFun(Rf_install("["), R_GlobalEnv));
  SETCAR(CDR(Rc_bracket), R_result);

#if 1
  PROTECT(R_tmp = NEW_INTEGER(0));
  SETCAR(CDDR(Rc_bracket),  R_tmp);
#endif

#if 0  
  PROTECT(R_tmp = allocVector(INTSXP, 0)); 
  SETCAR(CDDR(Rc_bracket),  R_tmp);
#endif

#if 0  
 SETCAR(CDDR(Rc_bracket),  R_NilValue);
#endif

#if 0  
 SETCAR(CDDR(Rc_bracket),  R_NilValue);
#endif

  PROTECT(R_tmp = NEW_INTEGER(1));
  INTEGER_DATA(R_tmp)[0] = 1; 
  SETCAR(CDR(CDR(CDR(Rc_bracket))), R_tmp);

  PROTECT(R_remainder = Test_tryEval(Rc_bracket, &hadError));
 
but I always failed. So, How do I correctly call the [ function? How learn 
from the source, which parameter has which function? And How do I generate an 
empty vector/list?

Thanks,
Alexander Schinner



More information about the R-devel mailing list