Lawrence Lee
Lawrence Lee

Reputation: 668

R Roxygen2: How to document a function generated by another function?

In my package, I have written a functional which takes a function as input and produce another function. How can I document a function produced via such a procedure?

Below is an illustration: use a functional to convert sin() (which takes radian input) to sind() which takes input in degree unit.

rad2deg <- function(f) {
  force(f)
  function(x) f(x / 180 * pi)
}

Here is some documentation for the function below...

sind <- rad2deg(sin)

The rad2deg is just my utility functional used by only me and thus not exported nor documented. I only need to export sind. But I have no idea how it can be done, as it is not even recognized as a function, and it doesn't even have a explicit argument (of course implicitly it takes the argument of the sin function). So, not even the @param tag can be used.

Is there anyone who have any idea?

Upvotes: 3

Views: 260

Answers (1)

TJ Mahr
TJ Mahr

Reputation: 3964

It works. The following code generates an Rd file and NAMESPACE directive for the sind function.

rad2deg <- function(f) {
  force(f)
  function(x) f(x / 180 * pi)
}

#' sin for degrees
#' @param x an angle in degrees
#' @return sin(x)
#' @export
sind <- rad2deg(sin)

Upvotes: 1

Related Questions