[Rd] Evaluating R expressions from C

Terry Therneau therneau at mayo.edu
Fri Jan 4 21:15:17 CET 2008


I am currently puzzled by a passage in the R Extensions manual, section 5.10:

SEXP lapply(SEXP list, SEXP expr, SEXP rho)
     {
       R_len_t i, n = length(list);
       SEXP ans;
     
       if(!isNewList(list)) error("`list' must be a list");
       if(!isEnvironment(rho)) error("`rho' should be an environment");
       PROTECT(ans = allocVector(VECSXP, n));
       for(i = 0; i < n; i++) {
         defineVar(install("x"), VECTOR_ELT(list, i), rho);
         SET_VECTOR_ELT(ans, i, eval(expr, rho));
       }
    
I'm trying to understand this code beyond just copying it, and don't find 
definitions for many of the calls.  PROTECT and SEXP have been well discussed 
previously in the document, but what exactly are
	R_len_t
	defineVar
	install
	VECTOR_ELT
	SET_VECTOR_ELT
	
The last I also found in 5.7.4, but it's not defined there either.  

So:
   What do these macros do?  Some I could guess, like is.Environment; and I'm 
fairly confident of R_len_t.  Others I need some help.
   Perhaps they are elswhere in the document?  (My version of acrobat can't do 
searches.)  Is there another document that I should look at first?
   Why "isNewList"?  I would have guessed "isList".  What's the difference?
   
   	Thanks for any help,
   		Terry Therneau



More information about the R-devel mailing list