[Roxygen-devel] parameters with default NULL value

Felix Andrews felix at nfrac.org
Tue Feb 2 05:28:40 CET 2010


Hi all,

I was just looking at this thread from a couple of weeks ago:
http://lists.r-forge.r-project.org/pipermail/roxygen-devel/2010-January/000115.html
proposing a change to the function parse.formals in parse.R.

However a more complete change is required to fix not just the "NULL"
bug but also the problem with long default arguments.

Rather than

  if (is.null(formals)) formals
  else list(formals=Map(function(formal)
              if (is.null(formal)) ''
              else if (is.call(formal)) capture.output(formal)
              else as.character(maybe.quote(formal)), formals))

I propose

  if (is.null(formals)) formals
  else list(formals = lapply(formals, function(formal)
      paste(deparse(formal, width=500, control=c()), collapse = "")
    )


Example:

foo <- function(x, d = NULL, a = "hi", asdasd = list(asd = list(x = 1)))
    { x }

lapply(formals(foo), function(formal)
      paste(deparse(formal, width=500, control=c()), collapse = "")
    )
$x
[1] ""

$d
[1] "NULL"

$a
[1] "\"hi\""

$asdasd
[1] "list(asd = list(x = 1))"




-- 
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 4670
E: felix.andrews at anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/


More information about the Roxygen-devel mailing list