我在Mac上工作,使用的是R的3.6.3版本,使用的是renv。在Rstudio和R中,我可以加载我安装的软件包的库,例如library(ggplot2) works。但是,当我使用Rscript运行脚本时,我收到以下消息
Error in library(ggplot2) : there is no package called ‘ggplot2’根据这个所以answer,我需要确保
Sys.getenv('R_LIBS_USER') in R.exe的值与
Rscript.exe -e ".libPaths()"但是值是相同的,两者都指向我的项目文件夹中的renv-system-library。
那么我该如何解决这个问题呢?
发布于 2020-04-15 06:13:24
我设法解决了这个问题。akruns的答案是有用的,它不工作,但给我指明了错误的方向。答案不起作用,因为使用它时,我收到以下错误:
Error: package or namespace load failed for ‘ggplot2’:
.onLoad failed in loadNamespace() for 'pillar', details:
call: utils::packageVersion("vctrs")
error: there is no package called ‘vctrs’现在vctrs在'/path/where/library/is/located'中,所以我认为依赖包不是从该路径加载的,而是Rscript的默认路径。在脚本中放入一个print(.libPaths()会给出
"/usr/local/Cellar/r/3.6.3_1/lib/R/library"而不是
[1] "/Users/Chris/Sites/app_name/renv/library/R-3.6/x86_64-apple-darwin18.7.0"
[2] "/private/var/folders/5_/p_yl0439059b7_jdqzrm0hr40000gr/T/RtmptdHcWN/renv-system-library"用于Rstudio中的.libPaths()。查看实际运行Rscript程序的ruby程序,我发现它是使用--vanilla选项运行的,即
Rscript --vanilla script_name删除--vanilla选项解决了这个问题。我认为带有--vanilla选项的脚本停止工作是因为我使用brew重新安装了R,以解决我遇到的另一个问题,并在其中发出了以下命令:
brew link --overwrite r 发布于 2020-04-14 05:06:41
在library调用中指定lib.loc可能更好
library(ggplot2, lib.loc = '/path/where/library/is/located')https://stackoverflow.com/questions/61196694
复制相似问题