Roxygen2 无法处理以下划线开头的文件?
Roxygen2 cannot process files begining with underscore?
我有一些小函数想添加到 R 包中。我在一个文件中列出了所有函数,每个函数前面都有用于构建帮助文件的 Roxygen2 指示(下面的示例)。一切正常。但是,我注意到当我将该文件重命名为以下划线开头(以便它出现在我的文件列表中的第一位)时,我收到以下错误消息:
Updating mypackage documentation
Loading mypackage
Writing NAMESPACE
Writing NAMESPACE
Warning message:
In setup_ns_exports(path, export_all, export_imports) :
Objects listed as exports, but not present in namespace: a, b
这是R子文件夹中唯一文件的内容:
#' @name a
#' @title the a() function does etc.
#' @description etc.
#' @param x a dataframe containing etc.;
#' @param v a vector containing etc..
#' @return a dataframe of the etc.
#' @export a
a <- function(x, v) { return("somevalue") }
#' @name b
#' @title the b() function does etc.
#' @description etc.
#' @param x a dataframe containing etc.;
#' @param v a vector containing etc..
#' @return a dataframe of the etc.
#' @export b
b <- function(x, v) { return("some other value") }
当我删除下划线并重新运行 devtools::document()
两次时,错误消息消失了。我放回下划线,错误又回来了。当没有 Roxygen2 标签时,没有错误,功能正常。
这是正常行为吗?有没有解决此错误的方法,还是我应该放弃使用下划线的想法?
它不(只是)roxygen2
,它是一个 R 东西。
来自 Writing R Extensions, subsection 1.1.5 Package subdirectories:
The R
subdirectory contains R code files, only. The code files to be installed must start with an ASCII (lower or upper case) letter or digit and have one of the extensions .R
, .S
, .q
, .r
, or .s
.
同样,
The man
subdirectory should contain (only) documentation files for the objects in the package in R documentation (Rd) format. The documentation filenames must start with an ASCII (lower or upper case) letter or digit and have the extension .Rd
(the default) or .rd
.
这通常不是使用 roxygen2
的问题:虽然它确实根据函数名称命名 .Rd
文件,并且 R 不允许函数名称(通常)以下划线。来自 R Language Definition subsection 10.3.2 Identifiers:
Identifiers consist of a sequence of letters, digits, the period (‘.’) and the underscore. They must not start with a digit or an underscore, or with a period followed by a digit.
虽然可以使用以下划线开头的标识符定义函数,但它需要将函数名称用反引号括起来以便定义和使用(因为它不是“有效标识符”)。
我有一些小函数想添加到 R 包中。我在一个文件中列出了所有函数,每个函数前面都有用于构建帮助文件的 Roxygen2 指示(下面的示例)。一切正常。但是,我注意到当我将该文件重命名为以下划线开头(以便它出现在我的文件列表中的第一位)时,我收到以下错误消息:
Updating mypackage documentation
Loading mypackage
Writing NAMESPACE
Writing NAMESPACE
Warning message:
In setup_ns_exports(path, export_all, export_imports) :
Objects listed as exports, but not present in namespace: a, b
这是R子文件夹中唯一文件的内容:
#' @name a
#' @title the a() function does etc.
#' @description etc.
#' @param x a dataframe containing etc.;
#' @param v a vector containing etc..
#' @return a dataframe of the etc.
#' @export a
a <- function(x, v) { return("somevalue") }
#' @name b
#' @title the b() function does etc.
#' @description etc.
#' @param x a dataframe containing etc.;
#' @param v a vector containing etc..
#' @return a dataframe of the etc.
#' @export b
b <- function(x, v) { return("some other value") }
当我删除下划线并重新运行 devtools::document()
两次时,错误消息消失了。我放回下划线,错误又回来了。当没有 Roxygen2 标签时,没有错误,功能正常。
这是正常行为吗?有没有解决此错误的方法,还是我应该放弃使用下划线的想法?
它不(只是)roxygen2
,它是一个 R 东西。
来自 Writing R Extensions, subsection 1.1.5 Package subdirectories:
The
R
subdirectory contains R code files, only. The code files to be installed must start with an ASCII (lower or upper case) letter or digit and have one of the extensions.R
,.S
,.q
,.r
, or.s
.
同样,
The
man
subdirectory should contain (only) documentation files for the objects in the package in R documentation (Rd) format. The documentation filenames must start with an ASCII (lower or upper case) letter or digit and have the extension.Rd
(the default) or.rd
.
这通常不是使用 roxygen2
的问题:虽然它确实根据函数名称命名 .Rd
文件,并且 R 不允许函数名称(通常)以下划线。来自 R Language Definition subsection 10.3.2 Identifiers:
Identifiers consist of a sequence of letters, digits, the period (‘.’) and the underscore. They must not start with a digit or an underscore, or with a period followed by a digit.
虽然可以使用以下划线开头的标识符定义函数,但它需要将函数名称用反引号括起来以便定义和使用(因为它不是“有效标识符”)。