[R] What is "args" in this function?

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Tue Aug 2 19:35:01 CEST 2016

Unfortunately for you, this email list is about R (not C), and while the Posting Guide indicates that questions discussing how to interface with C belong in R-devel, that is not a forum for learning C.

On the plus side,  the data types and macros you are asking questions about are highly specific to the implementation of R, so if you spend some time filling in your gaps in C on your own or in another forum, you ought be able to get answers to your questions on R-devel.

FWIW the R code you show does not appear (to me) to be what calls the C code you show... at least not directly. There should be a much more straightforward correspondence between the caller and callee than you imply here. 

Sent from my phone. Please excuse my brevity.

On August 2, 2016 9:06:55 AM PDT, Justin Thong <justinthong93 at gmail.com> wrote:
>Hi again I need help
>*model.matrix code*
>ans <- .External2(C_modelmatrix, t, data) #t =terms(object) ,
>frame of object"
>*modelframe C-code*
>SEXP modelframe(SEXP call, SEXP op, SEXP args, SEXP rho)
>SEXP terms, data, names, variables, varnames, dots, dotnames,
>    SEXP ans, row_names, subset, tmp;
>    char buf[256];
>    int i, j, nr, nc;
>    int nvars, ndots, nactualdots;
>    const void *vmax = vmaxget();
>    args = CDR(args);
>    terms = CAR(args); args = CDR(args);
>    row_names = CAR(args); args = CDR(args);
>    variables = CAR(args); args = CDR(args);
>    varnames = CAR(args); args = CDR(args);
>    dots = CAR(args); args = CDR(args);
>    dotnames = CAR(args); args = CDR(args);
>    subset = CAR(args); args = CDR(args);
>    na_action = CAR(args);
>. . . .
>I am sorry I virtually have no experience in C.
>Can someone explain to me what "args" is at the point when it enters
>function? I know CAR points to the first element of an object, and CDR
>points to the complement of the first element of an object.
>Does "args" represent the list of t and data?
>Does "args" represent the thrid argument in .External2 which is data?
>something else
>I am guessing this whole process of playing CAR and CDR is just a way
>extracting variables from "args" until everything thing in "args" is
>assigned to.
>For instance, if args=(1,2,3,4,5,6) then below correspond in square
>  args = CDR(args); [(1,2,3,4,5,6)]
>  terms = CAR(args) ;[(1)] args = CDR(args);[(2,3,4,5,6)]
>    row_names = CAR(args);[(2)] args = CDR(args);[(3,4,5,6)]
>    variables = CAR(args);[(3)] args = CDR(args);[(4,5,6)]
>    varnames = CAR(args);[(4)] args = CDR(args);[(5,6)]
>   etc
>Is this correct?
>I am sorry if I am asking too many questions on C. Please advise if I
>posting inappropriately.

More information about the R-help mailing list