使用 roxygen2 的 R 文档出错
Error in R documentation using roxygen2
构建 R 包后,在输入任何包的函数名称时出现此错误:
Error in gzfile(file, "rb") : cannot open the connection
Screenshot of the problem.
当 R 试图显示函数的提示(显示函数接受哪些参数的弹出窗口)时,显然会发生此错误。奇怪的是,使用 devtool 的 document() 函数后错误消失了。此外,帮助屏幕在输入“?function_name”后不会显示(在使用 document())
后有效
即使有这个错误包也能正常工作,问题是每次构建后,或者甚至只是在重新初始化 R 后再次加载包,这个错误又回来了,迫使用户使用 document() 来摆脱它,这很烦人。
我尝试重新安装 R,甚至 运行 在不同的系统上(起初我使用 windows 机器,但现在使用 ubuntu,问题仍然存在) .
还尝试创建其他几个测试包以查看错误是否特定于此包,但总是在创建的测试项目中第一次使用 document() 后,此错误开始发生。
我搜索了很多,最接近我找到类似问题的是以下 post,这似乎是同一个问题,但没有得到解决:
https://community.rstudio.com/t/error-connecting-to-help-documenation/881
下面是我如何使用 roxygen2 编写文档的示例。
//'@title title...
//'
//'@description description...
//'@param params...
//'@export
// [[Rcpp::export]]
Rcpp::DataFrame test(Rcpp::DataFrame arg1, Rcpp::DataFrame arg2) {
//code
}
任何人都可以解决这个问题吗?
编辑:
不使用 Rcpp 的项目似乎不会出现此问题,因此该错误可能与使用 roxygen2 的 Rcpp 文档有关。
这是一个 link 到 github 的包,它给我这个错误,以防有人想安装它并测试:
简而言之,您没有按照正确的顺序执行正确的命令。
你的 repo 本身很好(但需要工作)。
第 1 步:获取存储库
edd@rob:~$ mkdir /tmp/goldensushi
edd@rob:~$ cd /tmp/goldensushi/
edd@rob:/tmp/goldensushi$ git clone git@github.com:GoldenSushi/helpeR.git
Cloning into 'helpeR'...
remote: Counting objects: 186, done.
remote: Compressing objects: 100% (134/134), done.
remote: Total 186 (delta 42), reused 180 (delta 39), pack-reused 0
Receiving objects: 100% (186/186), 66.03 KiB | 1.54 MiB/s, done.
Resolving deltas: 100% (42/42), done.
edd@rob:/tmp/goldensushi$
第 2 步:compileAttributes 和 roxygenize
您必须先 运行 compileAttributes()
才能从 C++ 获取 Roxygen 标签
到 R,然后调用 roxygenize
来创建 Rd
文件。我为此使用了更小的脚本;其他人可能喜欢 devtools。不要紧。你
仍然必须调用正确的底层 R 函数。
edd@rob:/tmp/goldensushi$ cd helpeR/
edd@rob:/tmp/goldensushi/helpeR(master)$ compAttr.r # script: compileAttributes
edd@rob:/tmp/goldensushi/helpeR(master)$ roxy.r # script: roxygenize()
Loading required package: Rcpp
Warning: @export [RcppExports.R#10]: unknown tag
Warning: @export [RcppExports.R#18]: unknown tag
Warning: @export [RcppExports.R#32]: unknown tag
Warning: @useDynLib [_roxyTags.R#2]: unknown tag
Warning: @importFrom [_roxyTags.R#3]: unknown tag
Warning: @export [file_readers.R#8]: unknown tag
Warning: @export [tablemanip.R#6]: unknown tag
Warning message:
Version of roxygen2 last used with this package is 6.0.1.9000. \
You only have version 6.0.1
edd@rob:/tmp/goldensushi/helpeR(master)$
您在使用 roxygen 时似乎也有一些问题。
第 3 步:构建包
同样,我使用了我编写的帮助脚本(并在 littler 中发布)。不要紧。您需要调用正确的 R 脚本。
edd@rob:/tmp/goldensushi/helpeR(master)$ build.r # convenience script for R CMD build .
* checking for file ‘./DESCRIPTION’ ... OK
* preparing ‘helpeR’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* excluding invalid files
Subdirectory 'R' contains invalid file names:
‘_roxyTags.R’
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘helpeR_1.0.tar.gz’
edd@rob:/tmp/goldensushi/helpeR(master)$
第 4 步:检查包
我再次使用助手,这次是围绕 Gabor rcmdcheck()
。您也可以致电 R CMD check ...
edd@rob:/tmp/goldensushi/helpeR(master)$ rcc.r helpeR_1.0.tar.gz # convenience script for R CMD check
────────────────────────────────────────────────────────────────────────────────
─ using log directory ‘/tmp/file107a2d75f173/helpeR.Rcheck’
─ using R version 3.4.4 (2018-03-15)
─ using platform: x86_64-pc-linux-gnu (64-bit)
─ using session charset: UTF-8
✔ checking for file ‘helpeR/DESCRIPTION’
─ checking extension type ... Package
─ this is package ‘helpeR’ version ‘1.0’
✔ checking package namespace information
✔ checking package dependencies
W checking if this is a source package
Subdirectory ‘src’ contains:
environment_calls.hpp table.hpp valid.hpp
These are unlikely file names for src files.
✔ checking if there is a namespace
✔ checking for executable files
✔ checking for hidden files and directories
✔ checking for portable file names
✔ checking for sufficient/correct file permissions
─ checking whether package ‘helpeR’ can be installed ... [20s/17s] OK
✔ checking installed package size
✔ checking package directory
N checking DESCRIPTION meta-information
Malformed Title field: should not end in a period.
N checking top-level files
File
LICENSE
is not mentioned in the DESCRIPTION file.
✔ checking for left-over files
✔ checking index information
✔ checking package subdirectories
✔ checking R files for non-ASCII characters
✔ checking R files for syntax errors
✔ checking whether the package can be loaded
✔ checking whether the package can be loaded with stated dependencies
✔ checking whether the package can be unloaded cleanly
✔ checking whether the namespace can be loaded with stated dependencies
✔ checking whether the namespace can be unloaded cleanly
✔ checking loading without being on the library search path
✔ checking dependencies in R code
✔ checking S3 generic/method consistency
✔ checking replacement functions
✔ checking foreign function calls
N checking R code for possible problems
hread_table: no visible global function definition for ‘read.table’
Undefined global functions or variables:
read.table
Consider adding
importFrom("utils", "read.table")
to your NAMESPACE file.
✔ checking Rd files
✔ checking Rd metadata
✔ checking Rd cross-references
✔ checking for missing documentation entries
✔ checking for code/documentation mismatches
W checking Rd \usage sections
Undocumented arguments in documentation object 'neural.arrange'
‘x’
Functions with \usage entries need to have the appropriate \alias
entries, and all their arguments documented.
The \usage entries must correspond to syntactically valid R code.
See chapter ‘Writing R documentation files’ in the ‘Writing R
Extensions’ manual.
✔ checking Rd contents
✔ checking for unstated dependencies in examples
✔ checking line endings in C/C++/Fortran sources/headers
✔ checking compiled code
✔ checking examples
✔ checking PDF version of manual
See
‘/tmp/file107a2d75f173/helpeR.Rcheck/00check.log’
for details.
── 0 errors ✔ | 2 warnings ✖ | 3 notes ✖
edd@rob:/tmp/goldensushi/helpeR(master)$
简而言之:没有问题,当然 none 与 Rcpp。您只是对其中一些工具缺乏经验,所以我建议您尝试更多地了解它们。
后记
您或许可以使用这些不依赖于 littler 的替代命令:
edd@rob:/tmp/goldensushi/helpeR(master)$ Rscript -e 'Rcpp::compileAttributes()'
edd@rob:/tmp/goldensushi/helpeR(master)$ Rscript -e 'roxygen2::roxygenize()'
Loading required package: Rcpp
Warning message:
Version of roxygen2 last used with this package is 6.0.1.9000. You only have version 6.0.1
edd@rob:/tmp/goldensushi/helpeR(master)$ R CMD build .
* checking for file ‘./DESCRIPTION’ ... OK
[...]
* building ‘helpeR_1.0.tar.gz’
edd@rob:/tmp/goldensushi/helpeR(master)$ R CMD check helpeR_1.0.tar.gz
* using log directory ‘/tmp/goldensushi/helpeR/helpeR.Rcheck’
* using R version 3.4.4 (2018-03-15)
[...]
* checking PDF version of manual ... OK
* DONE
Status: 2 WARNINGs, 3 NOTEs
See
‘/tmp/goldensushi/helpeR/helpeR.Rcheck/00check.log’
for details.
edd@rob:/tmp/goldensushi/helpeR(master)$
构建 R 包后,在输入任何包的函数名称时出现此错误:
Error in gzfile(file, "rb") : cannot open the connection
Screenshot of the problem.
当 R 试图显示函数的提示(显示函数接受哪些参数的弹出窗口)时,显然会发生此错误。奇怪的是,使用 devtool 的 document() 函数后错误消失了。此外,帮助屏幕在输入“?function_name”后不会显示(在使用 document())
后有效即使有这个错误包也能正常工作,问题是每次构建后,或者甚至只是在重新初始化 R 后再次加载包,这个错误又回来了,迫使用户使用 document() 来摆脱它,这很烦人。
我尝试重新安装 R,甚至 运行 在不同的系统上(起初我使用 windows 机器,但现在使用 ubuntu,问题仍然存在) . 还尝试创建其他几个测试包以查看错误是否特定于此包,但总是在创建的测试项目中第一次使用 document() 后,此错误开始发生。
我搜索了很多,最接近我找到类似问题的是以下 post,这似乎是同一个问题,但没有得到解决:
https://community.rstudio.com/t/error-connecting-to-help-documenation/881
下面是我如何使用 roxygen2 编写文档的示例。
//'@title title...
//'
//'@description description...
//'@param params...
//'@export
// [[Rcpp::export]]
Rcpp::DataFrame test(Rcpp::DataFrame arg1, Rcpp::DataFrame arg2) {
//code
}
任何人都可以解决这个问题吗?
编辑:
不使用 Rcpp 的项目似乎不会出现此问题,因此该错误可能与使用 roxygen2 的 Rcpp 文档有关。
这是一个 link 到 github 的包,它给我这个错误,以防有人想安装它并测试:
简而言之,您没有按照正确的顺序执行正确的命令。
你的 repo 本身很好(但需要工作)。
第 1 步:获取存储库
edd@rob:~$ mkdir /tmp/goldensushi
edd@rob:~$ cd /tmp/goldensushi/
edd@rob:/tmp/goldensushi$ git clone git@github.com:GoldenSushi/helpeR.git
Cloning into 'helpeR'...
remote: Counting objects: 186, done.
remote: Compressing objects: 100% (134/134), done.
remote: Total 186 (delta 42), reused 180 (delta 39), pack-reused 0
Receiving objects: 100% (186/186), 66.03 KiB | 1.54 MiB/s, done.
Resolving deltas: 100% (42/42), done.
edd@rob:/tmp/goldensushi$
第 2 步:compileAttributes 和 roxygenize
您必须先 运行 compileAttributes()
才能从 C++ 获取 Roxygen 标签
到 R,然后调用 roxygenize
来创建 Rd
文件。我为此使用了更小的脚本;其他人可能喜欢 devtools。不要紧。你
仍然必须调用正确的底层 R 函数。
edd@rob:/tmp/goldensushi$ cd helpeR/
edd@rob:/tmp/goldensushi/helpeR(master)$ compAttr.r # script: compileAttributes
edd@rob:/tmp/goldensushi/helpeR(master)$ roxy.r # script: roxygenize()
Loading required package: Rcpp
Warning: @export [RcppExports.R#10]: unknown tag
Warning: @export [RcppExports.R#18]: unknown tag
Warning: @export [RcppExports.R#32]: unknown tag
Warning: @useDynLib [_roxyTags.R#2]: unknown tag
Warning: @importFrom [_roxyTags.R#3]: unknown tag
Warning: @export [file_readers.R#8]: unknown tag
Warning: @export [tablemanip.R#6]: unknown tag
Warning message:
Version of roxygen2 last used with this package is 6.0.1.9000. \
You only have version 6.0.1
edd@rob:/tmp/goldensushi/helpeR(master)$
您在使用 roxygen 时似乎也有一些问题。
第 3 步:构建包
同样,我使用了我编写的帮助脚本(并在 littler 中发布)。不要紧。您需要调用正确的 R 脚本。
edd@rob:/tmp/goldensushi/helpeR(master)$ build.r # convenience script for R CMD build .
* checking for file ‘./DESCRIPTION’ ... OK
* preparing ‘helpeR’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* excluding invalid files
Subdirectory 'R' contains invalid file names:
‘_roxyTags.R’
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘helpeR_1.0.tar.gz’
edd@rob:/tmp/goldensushi/helpeR(master)$
第 4 步:检查包
我再次使用助手,这次是围绕 Gabor rcmdcheck()
。您也可以致电 R CMD check ...
edd@rob:/tmp/goldensushi/helpeR(master)$ rcc.r helpeR_1.0.tar.gz # convenience script for R CMD check
────────────────────────────────────────────────────────────────────────────────
─ using log directory ‘/tmp/file107a2d75f173/helpeR.Rcheck’
─ using R version 3.4.4 (2018-03-15)
─ using platform: x86_64-pc-linux-gnu (64-bit)
─ using session charset: UTF-8
✔ checking for file ‘helpeR/DESCRIPTION’
─ checking extension type ... Package
─ this is package ‘helpeR’ version ‘1.0’
✔ checking package namespace information
✔ checking package dependencies
W checking if this is a source package
Subdirectory ‘src’ contains:
environment_calls.hpp table.hpp valid.hpp
These are unlikely file names for src files.
✔ checking if there is a namespace
✔ checking for executable files
✔ checking for hidden files and directories
✔ checking for portable file names
✔ checking for sufficient/correct file permissions
─ checking whether package ‘helpeR’ can be installed ... [20s/17s] OK
✔ checking installed package size
✔ checking package directory
N checking DESCRIPTION meta-information
Malformed Title field: should not end in a period.
N checking top-level files
File
LICENSE
is not mentioned in the DESCRIPTION file.
✔ checking for left-over files
✔ checking index information
✔ checking package subdirectories
✔ checking R files for non-ASCII characters
✔ checking R files for syntax errors
✔ checking whether the package can be loaded
✔ checking whether the package can be loaded with stated dependencies
✔ checking whether the package can be unloaded cleanly
✔ checking whether the namespace can be loaded with stated dependencies
✔ checking whether the namespace can be unloaded cleanly
✔ checking loading without being on the library search path
✔ checking dependencies in R code
✔ checking S3 generic/method consistency
✔ checking replacement functions
✔ checking foreign function calls
N checking R code for possible problems
hread_table: no visible global function definition for ‘read.table’
Undefined global functions or variables:
read.table
Consider adding
importFrom("utils", "read.table")
to your NAMESPACE file.
✔ checking Rd files
✔ checking Rd metadata
✔ checking Rd cross-references
✔ checking for missing documentation entries
✔ checking for code/documentation mismatches
W checking Rd \usage sections
Undocumented arguments in documentation object 'neural.arrange'
‘x’
Functions with \usage entries need to have the appropriate \alias
entries, and all their arguments documented.
The \usage entries must correspond to syntactically valid R code.
See chapter ‘Writing R documentation files’ in the ‘Writing R
Extensions’ manual.
✔ checking Rd contents
✔ checking for unstated dependencies in examples
✔ checking line endings in C/C++/Fortran sources/headers
✔ checking compiled code
✔ checking examples
✔ checking PDF version of manual
See
‘/tmp/file107a2d75f173/helpeR.Rcheck/00check.log’
for details.
── 0 errors ✔ | 2 warnings ✖ | 3 notes ✖
edd@rob:/tmp/goldensushi/helpeR(master)$
简而言之:没有问题,当然 none 与 Rcpp。您只是对其中一些工具缺乏经验,所以我建议您尝试更多地了解它们。
后记
您或许可以使用这些不依赖于 littler 的替代命令:
edd@rob:/tmp/goldensushi/helpeR(master)$ Rscript -e 'Rcpp::compileAttributes()'
edd@rob:/tmp/goldensushi/helpeR(master)$ Rscript -e 'roxygen2::roxygenize()'
Loading required package: Rcpp
Warning message:
Version of roxygen2 last used with this package is 6.0.1.9000. You only have version 6.0.1
edd@rob:/tmp/goldensushi/helpeR(master)$ R CMD build .
* checking for file ‘./DESCRIPTION’ ... OK
[...]
* building ‘helpeR_1.0.tar.gz’
edd@rob:/tmp/goldensushi/helpeR(master)$ R CMD check helpeR_1.0.tar.gz
* using log directory ‘/tmp/goldensushi/helpeR/helpeR.Rcheck’
* using R version 3.4.4 (2018-03-15)
[...]
* checking PDF version of manual ... OK
* DONE
Status: 2 WARNINGs, 3 NOTEs
See
‘/tmp/goldensushi/helpeR/helpeR.Rcheck/00check.log’
for details.
edd@rob:/tmp/goldensushi/helpeR(master)$