[Roxygen-devel] parameters with default NULL value
Charles Danko
dankoc at gmail.com
Fri Jan 22 15:14:29 CET 2010
Hi, Melissa,
This has been bugging me as well. Thanks for the fix! Any chance that this
will make it into the main source tree?
Best,
Charles
From: Melissa Jane Hubisz <mjhubisz at cornell.edu>
Date: Tue, Jan 19, 2010 at 10:31 AM
Subject: parameters with default NULL value
To: roxygen-devel at lists.r-forge.r-project.org
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.r-forge.r-project.org/pipermail/roxygen-devel/attachments/20100122/a1176658/attachment.htm
More information about the Roxygen-devel
mailing list