【问题标题】:attempt to apply non-function when using roxygenise(), can't find source of error使用 roxygenise() 时尝试应用非函数,找不到错误源
【发布时间】:2019-02-03 12:17:35
【问题描述】:

我正在尝试使用 roxygen2 将文档添加到我的任意 Rcpp 包中,但我不断收到相同的错误消息

> roxygen2::roxygenise("anRpackage")
First time using roxygen2. Upgrading automatically...
Error in .f(.x[[i]], ...) : attempt to apply non-function
In addition: Warning message:
roxygen2 requires Encoding: UTF-8 

我的源代码中没有“.f(.x[[i]])”,而且我无法识别“.f”形式。这是某种隐藏功能吗?我应该如何调试这个错误?我对编写 R 包很陌生,也许我遗漏了一些东西....提前致谢!

library(Rcpp)
library(RcppArmadillo)
library(roxygen2)
sessionInfo()

输出如下:

R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] roxygen2_6.1.0            RcppArmadillo_0.9.100.5.0 Rcpp_0.12.18             

loaded via a namespace (and not attached):
[1] compiler_3.4.2 R6_2.2.2       magrittr_1.5   tools_3.4.2    yaml_2.1.14   
[6] xml2_1.1.1     stringi_1.1.6  stringr_1.2.0  commonmark_1.4

【问题讨论】:

  • 您能否分享一下存储库或提供minimally complete verifiable example
  • 我刚试过你的命令序列:RcppArmadillo::RcppArmadillo.package.skeleton(); Rcpp::compileAttributes("anRpackage"); roxygen2::roxygenise("anRpackage");。这里没有错误消息。
  • Ralf Stubner 一样,我也运行了该命令序列,但没有收到任何错误消息。您可以运行以下命令并编辑您的问题以包含输出吗? library(Rcpp); library(RcppArmadillo); library(roxygen2); sessionInfo()
  • @lollipop R 版本,Rcpp、RcppArmadillo 和 roxygen2 版本,操作系统类型......
  • @lollipop 只包含sessionInfo() 的完整输出。那真的很有帮助...

标签: rcpp roxygen


【解决方案1】:

这不是答案,但我想记录我重现问题的失败尝试。由于我使用的是更新版本的 R 并且没有可用的 Windows 环境,因此我使用的是带有 R 版本的 docker 容器。准备工作

$ docker run --rm -it rocker/r-ver:3.4.2 bash
# apt-get update
# apt-get install libxml2-dev
# install2.r -r https://cloud.r-project.org/ RcppArmadillo roxygen2

会话信息:

> library(Rcpp)
> library(RcppArmadillo)
> library(roxygen2)
> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)

Matrix products: default
BLAS: /usr/lib/openblas-base/libblas.so.3
LAPACK: /usr/lib/libopenblasp-r0.2.19.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C             
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] roxygen2_6.1.0            RcppArmadillo_0.9.100.5.0
[3] Rcpp_0.12.18             

loaded via a namespace (and not attached):
[1] compiler_3.4.2 R6_2.2.2       magrittr_1.5   tools_3.4.2    xml2_1.2.0    
[6] stringi_1.1.6  stringr_1.2.0  commonmark_1.5

你的命令:

> RcppArmadillo.package.skeleton("anRpackage"); compileAttributes("anRpackage");roxygen2::roxygenise("anRpackage") 

Calling package.skeleton to create basic package.
Creating directories ...
Creating DESCRIPTION ...
Creating NAMESPACE ...
Creating Read-and-delete-me ...
Saving functions and data ...
Making help files ...
Done.
Further steps are described in './anRpackage/Read-and-delete-me'.

Adding RcppArmadillo settings
 >> added Imports: Rcpp
 >> added LinkingTo: Rcpp, RcppArmadillo
 >> added useDynLib and importFrom directives to NAMESPACE
 >> added Makevars file with Rcpp settings
 >> added Makevars.win file with RcppArmadillo settings
 >> added example src file using armadillo classes
 >> added example Rd file for using armadillo classes
 >> invoked Rcpp::compileAttributes to create wrappers
First time using roxygen2. Upgrading automatically...
Updating roxygen version in /anRpackage/DESCRIPTION
Loading anRpackage
Re-compiling anRpackage
Running /usr/local/lib/R/bin/R CMD INSTALL /anRpackage \
  '--library=/tmp/RtmpbM1VEb/devtools_install_7e040f6ccc8' --no-R --no-data \
  --no-help --no-demo --no-inst --no-docs --no-exec --no-multiarch \
  --no-test-load --preclean
* installing *source* package ‘anRpackage’ ...
** libs
g++ -std=gnu++11 -I/usr/local/lib/R/include -DNDEBUG  -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" -I/usr/local/include  -fopenmp  -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -UNDEBUG -Wall -pedantic -g -Og -fdiagnostics-color=always -c RcppExports.cpp -o RcppExports.o
g++ -std=gnu++11 -I/usr/local/lib/R/include -DNDEBUG  -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" -I/usr/local/include  -fopenmp  -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -UNDEBUG -Wall -pedantic -g -Og -fdiagnostics-color=always -c rcpparma_hello_world.cpp -o rcpparma_hello_world.o
g++ -std=gnu++11 -shared -L/usr/local/lib/R/lib -L/usr/local/lib -o anRpackage.so RcppExports.o rcpparma_hello_world.o -fopenmp -L/usr/local/lib/R/lib -lRlapack -lblas -lgfortran -lm -lquadmath -L/usr/local/lib/R/lib -lR
installing to /tmp/RtmpbM1VEb/devtools_install_7e040f6ccc8/anRpackage/libs
* DONE (anRpackage)
Warning: The existing 'NAMESPACE' file was not generated by roxygen2, and will not be overwritten.
Warning message:
roxygen2 requires Encoding: UTF-8 

我看到的唯一区别是操作系统和一些未附加的软件包,它们在我的 docker 容器中稍新。没有什么可以解释你的失败。

【讨论】:

  • 做得很好。另外,在最近的 Debian(和 Ubuntu)R 二进制包中,我现在还设置了默认的 CRAN 镜像(到相同的 CDN),因此您不再需要 -r 开关。 .deb 二进制文件当然也可用于 RcppArmadillo 和 roxygen2。
  • @DirkEddelbuettel 确实,如果我使用 rocker/r-base:3.4.2 而不是 rocker/r-ver:3.4.2 会更简单。
  • 宾果游戏。这是 Carl 从源代码为版本化堆栈构建的,因此它缺少其中一些包内自定义。所以我说的对于你使用的容器实际上是不正确的。我的错。
  • 大家好,我将我的 R 更新到最新版本并重新运行命令,一切顺利,没有错误。我仍然不明白为什么它以前不起作用.....非常感谢您的所有帮助
猜你喜欢
  • 1970-01-01
  • 2017-02-14
  • 1970-01-01
  • 2015-10-27
  • 2021-03-17
  • 1970-01-01
  • 1970-01-01
  • 2014-09-11
  • 1970-01-01
相关资源
最近更新 更多