From murdoch.duncan at gmail.com  Tue Nov  2 20:18:13 2010
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Tue, 02 Nov 2010 15:18:13 -0400
Subject: [Rd] on the usage of do.call
In-Reply-To: <AANLkTimou+OZmce9ERSQcTtitfhMO8DY=Qj6ahrkzLD6@mail.gmail.com>
References: <AANLkTimou+OZmce9ERSQcTtitfhMO8DY=Qj6ahrkzLD6@mail.gmail.com>
Message-ID: <4CD063F5.4040207@gmail.com>

On 02/11/2010 11:28 AM, 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 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.
>
> 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?

You would rarely want to use do.call from C.  You should use eval().  
See the examples in the Writing R Extensions manual, in the section 
"Evaluating R expressions from C".

Duncan Murdoch



[Rd] on the usage of do.call
Duncan Murdoch