[Roxygen-devel] parameters with default NULL value

Peter Danenberg pcd at roxygen.org
Fri Jan 22 15:16:53 CET 2010


Tell you the truth, this was bugging me as well; and I hadn't come up
with a good solution. Looks reasonable to me. What do you think,
Manuel?

> 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

> _______________________________________________
> Roxygen-devel mailing list
> Roxygen-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/roxygen-devel



More information about the Roxygen-devel mailing list