r-lib / devtools

Tools to make an R developer's life easier
https://devtools.r-lib.org
Other
2.37k stars 753 forks source link

Issue with multi-line examples #2419

Closed l-gorman closed 2 years ago

l-gorman commented 2 years ago

I have been using devtools for a while now, and I have found it has been fantastic. I have found one bug which I think might be worth flagging up.

I have found that there is a problem if you use #' to create multi-line comments within your functions, for example:

#' Title of My Function
#' 
#' Function description
#'
#' @param param1
#' @param param2
#' @param param3
#' 
#'  @return
#'  @export
#' 
#'  @examples
#' 
#'  bar <- "foo"
my_test_function <- function(param1, param2, param3){

#' Multi
#' line
#' comment
print("my test function")

}

What I have found is, if I run devtools::check(), I will get the following error:

base::assign(".ptime", proc.time(), pos = "CheckExEnv")
### Name: load_all_db_units
### Title: Load all db units
### Aliases: load_all_db_units
### ** Examples

loop over the possible list of unit conversion csv file names
Error: unexpected symbol in "Multi"
Execution halted

This is remedied when I replace #' with # within the function. It's absolutely fine if #' is not allowed within function, but it may be useful to have a warning/error which tells the user that the issue is with the type of comment used, and not with the actual examples they have made.

Thanks so much!

hadley commented 2 years ago

This is unfortunately the way that roxygen2 works; if you use a roxygen2 comment, it gets processed by roxygen2.