Roxygen2: feature request: documenting default argument values

Created on 3 Nov 2018  ·  2Comments  ·  Source: r-lib/roxygen2

Is there any possibility that roxygen2 can automatically add the default values for function arguments in the .Rd files?

For example,let's see this is the function:

foo <- function(x, d = 1) {
return(x + d)
}

In this case, I usually write something like-

#' @param x A numeric.
#' @param d A constant numeric value to add to `x` (Default : `1`).

But typically there are scores of such arguments with set default values and manually doing it means-

  • this will be highly time-consuming
  • this will be highly error-prone since I can change the default value (d = 2) and forget to update the documentation

If roxygen2 can automatically add the default values at the end of the param description text, that would be really neat.

Most helpful comment

Well, the defaults are already in the manual, in the _Usage_ section. I agree that it can be nice to have them in the _Arguments_ section as well, but I am not sure how easy that would be to implement. Probably not too bad.

this will be highly error-prone since I can change the default value (d = 2) and forget to update the documentation

Yes, R CMD check will catch discrepancies in the _Usage_ section, though.

All 2 comments

Well, the defaults are already in the manual, in the _Usage_ section. I agree that it can be nice to have them in the _Arguments_ section as well, but I am not sure how easy that would be to implement. Probably not too bad.

this will be highly error-prone since I can change the default value (d = 2) and forget to update the documentation

Yes, R CMD check will catch discrepancies in the _Usage_ section, though.

To me, repeating in the argument section is not terribly useful, and will require a decent amount of work because we'd need some package wide option to control the behaviour and give the user control over the precise appearance.

Was this page helpful?
0 / 5 - 0 ratings