On Mar 27, 2012, at 12:03 PM, Terry Therneau wrote:

> On 03/23/2012 10:58 AM, Simon Urbanek wrote:
>> This is my shot at a cheat sheet.
>> comments are welcome.
>> Simon
> I was looking through the cheat sheet.  It's nice.  There are a few things in 
> it that I can't find in the documentation though.  Where would one find a 
> description?  (I can guess, but that may be dangerous).
> mkNamed

It is a shorthand for using allocVector and then setting names (which can be 
tedious). It's a simple way to create a result list/object (a very common thing 
to do):

    SEXP res = PROTECT(mkNamed(VECSXP, (const char*[]) { "foo", "bar", ""}));
    // fill res with SET_VECTOR_ELT(res, ..) 
    setAttrib(res, R_ClassSymbol, mkString("myClass"));
    return res;

Note that the sentinel is "" (not not NULL as commonly used in other APIs). 
Also you don't specify the length because it is determined from the names.

> R_Naint   (I don't see quite how this differs from using NA_INTEGER to set a 
> result)

It doesn't really -- NA_INTEGER is defined to be R_NaInt. In theory NA_INTEGER 
being a macro could be a constant instead -- maybe for efficiency -- but 
currently it's not.

> R_PreserveObject, R_ReleaseObject   (Advantages/disadvantages wrt PRESERVE?)

I guess you mean wrt PROTECT? Preserve/Release is used for objects that you 
want to be globally preserved - i.e. they will survive exit from the function. 
In contrast, the protection stack is popped when you exit the function (both by 
error or success).


R-devel@r-project.org mailing list

Reply via email to