无法从 Rscript 批处理文件调用 roxygenize 函数

发布于 2024-12-28 12:18:49 字数 724 浏览 5 评论 0原文

我正在编写一个使用 roxygen2 来自动 roxygenize 我的包的脚本。我希望它是可执行的,以便它可以成为更大脚本的一部分来准备和安装包,但由于某种原因我无法使其与 Rscript 一起使用。

代码如下:

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

如果我启动交互式 R 会话或者使用 R CMD BATCH 提交代码,则该代码可以正常工作。但是,如果我通过 Rscript 直接将脚本作为可执行文件运行,我会得到此输出和错误(并且无论脚本是否位于当前目录或 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

看起来 setPackageName 在基本 R 中,所以我不明白为什么它不在那里。此外,我在许多其他情况下使用 Rscript,这似乎是它唯一失败的地方。

非常感谢任何帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小红帽 2025-01-04 12:18:49

在加载 roxygen2 和调用 roxygenize() 之前显式加载包 methodsutils

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

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文