2

I would like to automatically generate documentation for my R functions and I've already come across the package roxygen2, which almost fulfills my needs. However, I would like to include in my documentation whole chunks of code without having to enclose them with #' '''. Practically speaking, in the example below I would like to automatically include

add <- function(x, y) {
  x + y
}

in my "sum.rd" file as it is (i.e., without having to duplicate it in file "sum.R" and enclose it in #' ''').

Is there any way to achieve this?


file "sum.R":

#' Add together two numbers \
#' @param x A number \
#' @param y A number \
#' @return The sum of \code{x} and \code{y} \
#' @examples \
#' add(1, 1) \
#' add(10, 1) \
add <- function(x, y) { \
  x + y \
}
euterpe87
  • 21
  • 2
  • You probably could use a template like described in [this answer](https://stackoverflow.com/a/57101578/9349302). However, you would still need to wrap the function in `#'` in the template itself, so this won't be your desired solution, I guess. – TimTeaFan Jan 05 '21 at 12:25
  • Might be better to put it in a vignette and then just reference that in the help file. – G. Grothendieck Jan 05 '21 at 16:13

0 Answers0