4

Are there versions of parent.frame or sys.calls or other general context functions that can be called directly from C code invoked by .Call? Looking around the Rinternals.h, etc, I can't seem to find anything of the sort. The best I can come up with is something like:

my_fun <- function(x) {
   .Call(my_fun_C, substitute(x), parent.frame(), sys.calls())
}

but ideally I'd prefer to avoid the R calls to substitute, parent.frame, etc. and do those directly from C. Why? Each of those function calls adds 300ns to the evaluation of my_fun, and while that isn't exactly going to kill me, I'd like to know if there is a way to avoid it or if I'm stuck with the above.

There is this tantalizing tidbit of code from main/context.c in the function do_sys:

RCNTXT *cptr;

cptr = R_GlobalContext;
t = cptr->sysparent;

but RCNTXT is defined in includes/Defn.h, and Defn.h looks to be an internal non-exported header.

BrodieG
  • 51,669
  • 9
  • 93
  • 146
  • Looks like Eddi explores something similar in **[this question](http://stackoverflow.com/questions/19686892/passing-unevaluated-expressions-to-c-c)**. – BrodieG Sep 19 '14 at 15:29

0 Answers0