[Rd] on the usage of do.call

Matt Shotwell shotwelm at musc.edu
Tue Nov 2 20:08:47 CET 2010

On Tue, 2010-11-02 at 11:28 -0400, Christophe Dutang wrote:
> Hello all,
> I don't know if it is possible, but I would like to use do.call in C code in
> my package. The function do.call is defined as
> > do.call
> function (what, args, quote = FALSE, envir = parent.frame())
> {
>     if (!is.list(args))
>         stop("second argument must be a list")
>     if (quote) {
>         enquote <- function(x) as.call(list(as.name("quote"),
>             x))
>         args <- lapply(args, enquote)
>     }
>     .Internal(do.call(what, args, envir))
> }
> <environment: namespace:base>
> >
> In <src>/main/names.c, the function do.call is linked to the C function
> do_docall (line 499). (.Internal calls the good function line 1194.)
> And the do_docall function is defined in <src>/main/coerce.c line 2217 and
> declared as
>   SEXP attribute_hidden do_docall(SEXP call, SEXP op, SEXP args, SEXP rho)
> in Internal.h.

The 'attribute_hidden' declaration indicates do_docall was not intended
for use by package developers. That's also why it's not part of the
installed headers. See 'Writing R Extensions', the section titled
'Controlling Visibility'.

> The problem is that I do not guess the exact meaning of theses arguments,
> and the header file Internal.h is not found when included in my C file.

I'm not sure there are any biolerplate descriptions of this common
prototype. The are some hints in "R Internals" chapter 2 and the source
file /src/main/names.c.

> As this header is not listed in R-exts.pdf section 6.17, I think I cannot
> use the do_docall function.
> Does anyone face this problem? or have an idea on how to solve it?

Some ideas, in good-to-bad order:

1. look for a solution not involving do.call
2. modularize your C code, such that do.call may be used at R level
3. use call() at R level, pass result + envir to C code for later eval()
4. emulate do_docall in custom C code

> Thanks in advance
> Christophe

Matthew S. Shotwell
Graduate Student 
Division of Biostatistics and Epidemiology
Medical University of South Carolina

More information about the R-devel mailing list