当在函数内部发生#'时,roxygen2(版本5.0)错误地创建了文档

时间:2021-01-08 14:57:20

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

考虑以下R函数定义,使用roxygen2进行记录(版本> = 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:

当使用devtools :: document()来记录它时,它会产生以下错误:

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

警告消息:1:@examples [TestFun.R#8]:大括号或引号不匹配

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

请注意,“示例”部分中绝对没有不匹配的大括号或引号。是什么造成的?我该如何解决?

1 个解决方案

#1


6  

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

这是由于roxygen2包的最近变化。来自新闻:

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.

现在还记录了记录的函数的内容以用于roxygen注释。这允许例如将参数的类型记录到接近于检查该类型的位置,或者记录接近源的实现细节,并简化将来的扩展,例如R6类的文档。

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.

这意味着将解析代码块内的任何roxygen风格的注释。如果你的包的代码在函数内包含这样的注释,你可能想用简单的注释替换它们,即用#替换#'。在这次一次性更改之后,除非有意,否则不要再在代码块中使用roxygen风格的注释。

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)将所有空格缩进的roxygen样式注释替换为当前目录的R /子目录中所有文件中的普通注释:

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

Adapt it to your needs.

根据您的需求进行调整。

#1


6  

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

这是由于roxygen2包的最近变化。来自新闻:

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.

现在还记录了记录的函数的内容以用于roxygen注释。这允许例如将参数的类型记录到接近于检查该类型的位置,或者记录接近源的实现细节,并简化将来的扩展,例如R6类的文档。

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.

这意味着将解析代码块内的任何roxygen风格的注释。如果你的包的代码在函数内包含这样的注释,你可能想用简单的注释替换它们,即用#替换#'。在这次一次性更改之后,除非有意,否则不要再在代码块中使用roxygen风格的注释。

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)将所有空格缩进的roxygen样式注释替换为当前目录的R /子目录中所有文件中的普通注释:

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

Adapt it to your needs.

根据您的需求进行调整。