像在 Rstudio 中一样使用 Rcpp 安装 R 包的终端命令?

Terminal commands to install R packages with Rcpp like in Rstudio?

我最近在使用 R 代码时从 Rstudio 迁移到 vim。当我在 Rstudio 中单击 Install and Restart 时,我无法理解如何复制发送的命令。

据我了解,我需要运行

Rscript -e "Rcpp::compileAttributes()"
Rscript -e "devtools::document()"

复制 Rstudio 的 Document 按钮。那么

Rscript -e "Rcpp::compileAttributes()"
R CMD INSTALL --no-multiarch --with-keep.source .

应该复制 Install and Restart 按钮。

问题是:使用 Rstudio 的按钮可以很好地安装包,而 运行 宁命令不会。尝试 document() 时出现以下错误:

Updating mypkg documentation
Writing NAMESPACE
Loading mypkg
Error in representation(N = "numeric", N_dep = "numeric", vertices = "list",  : could not find function "representation"
Calls: <Anonymous> ... source_many -> source_one -> eval -> eval -> setClass -> is
Execution halted

如果我忽略它并只安装包,包中唯一可用的对象是 my_kpg::'.__t__[[:base'。我怎样才能构建一系列与 Rstudio 的 DocumentInstall and Restart 按钮行为相同的命令行输入?

原来 Rscript 默认情况下不加载 methods 包,而交互式 R 会话会加载(很奇怪)。问题是由于缺少包造成的。

library(methods) 添加到我的 .Rprofile 文件解决了这个问题。