[R] Functioning and source code location of .Primitive()

Stefano Baraldo stefano.baraldo at gmail.com
Mon May 24 15:07:07 CEST 2010


Thank you Barry!
Telling the truth, I found the function definition this morning too... I really don't know how could I have missed it (I've been searching for it for a pair of days...). I work on a Mac and I'm learning to use Unix systems in general, so I'm not very accustomed to grep and emacs. I'll definitely follow your tip.
Anyway, the question is just shifted now, even tracking down C function calls I still don't understand completely how the function evaluation is carried out. I'll continue studying, and eventually write on the R-dev list.
Thank you again

Stefano


Il giorno 24/mag/2010, alle ore 11.02, Barry Rowlingson ha scritto:

> On Mon, May 24, 2010 at 9:03 AM, Stefano Baraldo
> <stefano.baraldo a gmail.com> wrote:
>> Hi all.
>> I began examining the R source code in the last few days, for a better understanding of its structure. I read the manuals and digged deeply (maybe not enough?) into the source code, but I couldn't totally understand how .Primitive() works. Its effects, if I understand well, are quite clear to me (calling the C compiled counterpart of a "primitive" function), but where is its definition? The only things I was able to find were:
>> -in src/library/base/R/zzz.R, its creation in the .ArgsEnv environment, but with NULL body!
>> -in src/main/names.c, the association of .Primitive() to the C function do_primitive, which I cannot find anywhere else in the source code.
>> Does any of you know where should I look?
> 
> First, I reckon you should be looking on the r-dev mailing list! :)
> 
> Secondly, if you are using a Unix machine with GNU utils, 'grep -nr'
> is your friend:
> 
> $ grep -nr do_primitive .
> ./src/gnuwin32/Rdll.hide:864: do_primitive
> ./src/include/Internal.h:365:SEXP do_primitive(SEXP, SEXP, SEXP, SEXP);
> ./src/main/names.c:117:{".Primitive",	do_primitive,	0,	1,	1,	{PP_FUNCALL,
> PREC_FN,	  0}},
> ./src/main/names.c:1008:SEXP attribute_hidden do_primitive(SEXP call,
> SEXP op, SEXP args, SEXP env)
> 
>  - so I'm not sure why you didn't spot the do_primitive definition on
> line 1008:
> 
> SEXP attribute_hidden do_primitive(SEXP call, SEXP op, SEXP args, SEXP env)
> {
>    SEXP name;
>    int i;
>    checkArity(op, args);
>    name = CAR(args);
>    if (!isString(name) || length(name) < 1 ||
> 
> etc etc.
> 
> If you are going to do a lot of this kind of nosing around, it's
> worth looking at an IDE that can help by tracking where function
> definitions are. For example, emacs with the etags system. Tutorial
> here:
> 
> http://www.linuxjournal.com/article/2821?page=0,1
> 
> Barry



More information about the R-help mailing list