Cannot call roxygenize function from Rscript batch file

微笑、不失礼 提交于 2020-02-02 01:29:13

问题


I am writing a script that uses roxygen2 to automatically roxygenize my package. I'd like it to be executable so that it can be part of a larger script to prepare and install the package, but I cannot make it work with Rscript for some reason.

Here is the code:

#!/usr/bin/env Rscript
library(roxygen2)
roxygenize('.', copy=FALSE)

This works correctly if I start an interactive R session or if I submit the code using R CMD BATCH. However, I get this output and error if I run the script directly as an executable via Rscript (and I get the error regardless of whether the script is in the current directory or bin).

bin/roxygenize.R 
Loading required package: digest
Warning message:
package 'roxygen2' was built under R version 2.13.2 
Error in parse.files(r_files) : could not find function "setPackageName"
Calls: roxygenize -> parse.files
Execution halted

It looks like setPackageName is in base R, so I can't figure out why it's not there. Additionally, I use Rscript in lots of other situations and this seems to be the only place that it fails.

Any help is much appreciated.


回答1:


Explicitly load the packages methods and utils before loading roxygen2 and calling roxygenize().

#!/usr/bin/env Rscript
library(methods)
library(utils)
library(roxygen2)
roxygenize('.', copy=FALSE)


来源:https://stackoverflow.com/questions/8964515/cannot-call-roxygenize-function-from-rscript-batch-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!