[Roxygen-devel] parameters with default NULL value
Melissa Jane Hubisz
mjhubisz at cornell.edu
Tue Jan 19 16:31:49 CET 2010
Hello,
I've been developing a fairly large package in R and was thrilled to
discover roxygen. Thank you for providing this useful tool!
I have been using the most recent version of roxygen from the SVN
repository. One problem I have encountered is that the "usage" is not
displayed properly if a function has parameters whose default value is
NULL. For example, the function:
myfunc <- function(a, b=NULL, c=0) {NULL}
will have the documentation:
Usage:
myfunc(a, b, c=0)
which incorrectly implies that b is a required parameter.
I did a bit of poking around and this seems to have a simple fix, by
changing the function parse.formals in parse.R to:
parse.formals <- function(expressions) {
formals <- NULL
call <- car(expressions)
if (is.call(call)) {
f <- cadr(expressions)
if (is.function.definition(f))
formals <- tryCatch(formals(eval(call)),
error=function(e) NULL)
}
if (is.null(formals)) formals
else list(formals=Map(function(formal)
if (is.null(formal)) 'NULL' #THIS IS THE
ONLY CHANGE, it used to be the empty string ''
else if (is.call(formal)) capture.output(formal)
else as.character(maybe.quote(formal)), formals))
}
Not being very familiar with the inner workings of roxygen, I'm not
sure if this hack will break anything else, but it seems to work for
me. If it is a proper solution, could it be incorporated into
roxygen? If not, is there another way to fix this?
Thanks again for your work on this. It's been a huge timesaver for me.
-Melissa
Melissa Hubisz
Department of Biological Statistics and Computational Biology
Cornell University
More information about the Roxygen-devel
mailing list