From therneau at mayo.edu  Fri Jan  4 21:15:17 2008
From: therneau at mayo.edu (Terry Therneau)
Date: Fri, 4 Jan 2008 14:15:17 -0600 (CST)
Subject: [Rd] Evaluating R expressions from C
Message-ID: <200801042015.m04KFHF03452@hsrnfs-101.mayo.edu>

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



[Rd] Evaluating R expressions from C
Terry Therneau