我不确定此问题是否曾被提出,但我乍看之下并没有看到任何问题。尝试使用以下命令从控制台运行R脚本时,我正在努力使用R库路径:
Rscript myfile.R
myfile.R中加载的库未正确加载。在RStudio中,我的库路径是:
# run from console in RStudio
> .libPaths()
[1] "/Library/Frameworks/R.framework/Versions/3.4/Resources/library"
> version
_
platform x86_64-apple-darwin15.6.0
arch x86_64
os darwin15.6.0
system x86_64, darwin15.6.0
status
major 3
minor 4.1
year 2017
month 06
day 30
svn rev 72865
language R
version.string R version 3.4.1 (2017-06-30)
nickname Single Candle
但是,当我从命令行检查R的库路径时,我收到以下错误路径:
Rscript -e 'print(.libPaths())'
[1] "/Users/Home/anaconda2/lib/R/library"
Rscript -e 'print(version)'
_
platform x86_64-apple-darwin11.4.2
arch x86_64
os darwin11.4.2
system x86_64, darwin11.4.2
status
major 3
minor 2.2
year 2015
month 08
day 14
svn rev 69053
language R
version.string R version 3.2.2 (2015-08-14)
nickname Fire Safety
返回的RStudio路径实际上没有显示前缀,实际上是:
/Users/Home/Library/Frameworks/R.framework/Versions/3.4/Resources/library
所以我的问题是,如何使用.libPaths()为我的R库更改错误的路径(在终端中运行)到正确的路径(在RStudio中运行)?
谢谢!