Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

roxygen2 (Version 5.0) incorrectly creates documentation when #' occurs inside function

Tags:

r

roxygen2

Consider the following R function definition, to be documented using roxygen2 (version >=5.0)

#' @title Test Bug
#' @author Daniel Egan
#' @param x  
#' @return Nothing
#' @export
#' @examples
#' testFun(x)


testFun <- function(x){

  #' Warning1'
  return(TRUE)
}

When using devtools::document() to document this, it produces the following error:

Warning messages:
1: @examples [TestFun.R#8]: mismatched braces or quotes

Note that there are DEFINITELY no mismatched braces or quotes in the "examples" section. What is causing this? How can I fix it?

like image 554
Daniel Egan Avatar asked Nov 04 '15 18:11

Daniel Egan


1 Answers

This is due to recent changes in the roxygen2 package. From the NEWS:

The contents of documented functions are now also parsed for roxygen comments. This allows, e.g., documenting a parameter's type close to where this type is checked, or documenting implementation details close to the source, and simplifies future extensions such as the documentation of R6 classes.

This means that any roxygen-style comments inside code blocks will be parsed. If your package's code contains such comments inside functions, you probably want to substitute them with plain comments, i.e., replace #' by #. After this one-time change, simply don't use roxygen-style comments in code blocks anymore, unless intended.

The following command line (requires sed) substitutes all space-indented roxygen-style comments with plain comments in all files in the R/ subdirectory of the current directory:

sed -r -i"" "s/( +#)'/\1/" R/*

Adapt it to your needs.

like image 133
krlmlr Avatar answered Nov 02 '22 21:11

krlmlr