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

Justin Thong justinthong93 at gmail.com
Tue Aug 2 18:06:55 CEST 2016

Hi again I need help


*model.matrix code*
ans <- .External2(C_modelmatrix, t, data) #t =terms(object) , data="data
frame of object"

*modelframe C-code*
SEXP modelframe(SEXP call, SEXP op, SEXP args, SEXP rho)
    SEXP terms, data, names, variables, varnames, dots, dotnames, na_action;
    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 the
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 of
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)]

Is this correct?

I am sorry if I am asking too many questions on C. Please advise if I am
posting inappropriately.

Yours sincerely,

*I check my email at 9AM and 4PM everyday*
*If you have an EMERGENCY, contact me at +447938674419(UK) or

	[[alternative HTML version deleted]]

More information about the R-help mailing list