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

From: Peter Meilstrup <peter.meilstrup_at_gmail.com>
Date: Wed, 03 Oct 2012 19:37:24 -0700

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=).

"missing" seems different from NULL; if I do

arglist <- rep(list(NULL), length(argnames)) names(arglist) <- argnames
make_function(arglist, quote(a+b+c))

I get a function where NULL is the default value for each argument, rather than a function with no default values.

It seems I can assign a "missing value" to a variable by

the_missing_value <- formals(function(x) NULL)[[1]]

or by

the_missing_value = quote(expr=)

However this backfires when I try to use it:

> arglist <- rep(list(the_missing_value), length(argnames))
Error in list(the_missing_value) : 'the_missing_value' is missing

> arglist <- rep(list(NULL), 3)
> arglist[] <- the_missing_value

Error: argument "the_missing_value" is missing, with no default

Besides which, roxygen2 (and other package tools) choked on encountering a missing value assigned to a name in my package.

So, what's going on with missing? Missing and '...' are the two pieces of R's semantics I'm most fuzzy on.

(Somewhere along this experimentation I also managed to assign a value to the empty name, and could not figure out how to remove it...)


R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 04 Oct 2012 - 02:40:00 GMT

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

All messages

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 Thu 04 Oct 2012 - 20:50:44 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.

list of date sections of archive