簡體   English   中英

使用roxygen2的R文檔中的錯誤

[英]Error in R documentation using roxygen2

構建R程序包后,在鍵入任何程序包的函數名稱時出現此錯誤:

Error in gzfile(file, "rb") : cannot open the connection

問題的屏幕截圖。

當R嘗試顯示該函數的提示時(該彈出窗口顯示該函數接受哪些參數),顯然會發生此錯誤。 奇怪的是,使用devtool的document()函數后錯誤消失了。 此外,輸入“?function_name”后,幫助屏幕將不會顯示(在使用document()之后有效)

即使出現此錯誤,程序包也可以正常工作,問題是每次構建后,甚至在重新初始化R之后只是再次加載程序包,此錯誤都會再次出現,迫使用戶使用document()擺脫它,這是煩人。

我試圖重新安裝R,甚至在其他系統上運行(起初我使用的是Windows計算機,但是現在,使用ubuntu,問題仍然存在)。 還嘗試創建其他幾個測試包以查看該錯誤是否特定於此包,但是始終在創建的測試項目中首次使用document()之后,此錯誤開始發生。

我進行了很多搜索,發現以下類似的問題是我發現的最接近的類似問題,但並沒有得到解決:

https://community.rstudio.com/t/error-connecting-to-help-documenation/881

以下是我如何使用roxygen2編寫documentatin的示例。

//'@title title...
//'
//'@description description...
//'@param params...
//'@export
// [[Rcpp::export]]
Rcpp::DataFrame test(Rcpp::DataFrame arg1, Rcpp::DataFrame arg2) {

    //code

}

有人能闡明這個問題嗎?

編輯:

似乎該問題不會發生在不使用Rcpp的項目中,因此該錯誤可能與使用roxygen2的Rcpp文檔有關。

這是指向github上一個軟件包的鏈接,如果有人要安裝和測試該軟件包,則會給我這個錯誤:

https://github.com/GoldenSushi/helpeR

簡而言之,您沒有以正確的順序執行正確的命令。

您回購本身就可以了(但需要工作)。

第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和重新充氧

您必須先運行compileAttributes()才能將Roxygen標記從C ++轉換為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)$ 

您似乎也無法使用氧氣。

步驟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)$ 

簡而言之:沒有問題,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)$ 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM