[Rd] How to build a list with missing values? What is missing, anyway?

Hadley Wickham h.wickham at gmail.com
Thu Oct 4 05:10:00 CEST 2012

On Wed, Oct 3, 2012 at 9:37 PM, Peter Meilstrup
<peter.meilstrup at gmail.com> wrote:
> This is tangentially related to Hadley's question.
> Suppose I'm building a function programmatically; I have assembled an
> expression for the body and I know the names of the arguments it wants
> to take.
> Suppose I have some convenience function such that writing
>     make_function(alist(a=, b=), quote(a+b), environment())
> is equivalent to writing
>     function(a,b) a+b
> So how do I make the list that goes in the first argument? Suppose I
> start with a character vector of argument names. What I need is a list
> with names and quoted values, but the values are "empty".
> Say I have argnames <- c("a", "b", "c").
> >From that I want to construct the equivalent of alist(a=, b=, c=).

Here's one approach:

args <- alist()
for (n in argnames) {
  args[[n]] <- bquote()

You have to be really careful dealing with the missing symbol, because
if R attempts to evaluate it, you get the missing argument error.


RStudio / Rice University

More information about the R-devel mailing list