From: Hadley Wickham <h.wickham_at_gmail.com>

Date: Wed, 03 Oct 2012 22:10:00 -0500

Date: Wed, 03 Oct 2012 22:10:00 -0500

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.

Hadley

-- RStudio / Rice University http://had.co.nz/ ______________________________________________ R-devel_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-develReceived on Thu 04 Oct 2012 - 03:13:00 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

*
Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.
Archive generated by hypermail 2.2.0, at Fri 05 Oct 2012 - 06:42:51 GMT.
*

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel.
Please read the posting
guide before posting to the list.
*