FWIW: I have put the (slightly updated) sheet at

http://r.research.att.com/man/R-API-cheat-sheet.pdf

Note that it is certainly incomplete - but that is intentional to a) to fit the 
space constraints and b) to show only the most basic things since we are 
talking about starting with .Call -- advanced users may need a different sheet 
but then they just go straight to the headers anyway ...

Cheers,
Simon




On Mar 27, 2012, at 12:20 PM, Simon Urbanek wrote:

> 
> 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"));
>    UNPROTECT(1);
>    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).
> 
> Cheers,
> Simon
> 
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to