RStudio和命令行R之间的区别。

时间:2021-04-28 20:45:48

When I run R from the command line:

当我从命令行运行R时:

> library(ggplot2)
...
> path.package('ggplot2')
[1] "/home/yang/R/x86_64-pc-linux-gnu-library/2.13/ggplot2"
> .libPaths()
[1] "/home/yang/R/x86_64-pc-linux-gnu-library/2.13"
[2] "/usr/local/lib/R/site-library"                
[3] "/usr/lib/R/site-library"                      
[4] "/usr/lib/R/library"                           
> Sys.getenv('R_LIBS_USER')
[1] "~/R/x86_64-pc-linux-gnu-library/2.13"

(Note: that environment variable actually doesn't exist when I check from my shell.)

(注意:当我从shell中检查时,该环境变量实际上并不存在。)

But from RStudio Server running on the same box, and after logging in as the same user:

但是从运行在同一个盒子上的RStudio Server,以及登录到同一个用户之后:

> path.package('ggplot2')
[1] "/home/yang/R/library/ggplot2"
> .libPaths()
[1] "/home/yang/R/library"              "/usr/local/lib/R/site-library"    
[3] "/usr/lib/R/site-library"           "/usr/lib/R/library"               
[5] "/usr/lib/rstudio-server/R/library"
> Sys.getenv('R_LIBS_USER')
[1] "/home/yang/R/library"

Can you explain why these are different by default? Is this an RStudio customization? (Why?) Thanks in advance.

你能解释一下为什么它们在默认情况下是不同的吗?这是RStudio定制吗?(为什么?)提前谢谢。

2 个解决方案

#1


6  

A quick googling got me here:

我用谷歌搜索了一下:

http://support.rstudio.org/help/discussions/problems/868-how-to-configure-libpaths

http://support.rstudio.org/help/discussions/problems/868-how-to-configure-libpaths

so it looks like RStudio uses its own libs, set in /etc/rstudio/rsession.conf. Why? Who knows.

因此,RStudio使用自己的libs,设置在/etc/rstudio/rsession.conf中。为什么?谁知道呢。

#2


7  

Direct answer from the source:

直接回答来源:

http://support.rstudio.org/help/discussions/questions/204-r-libpaths-difference-between-rstudio-and-command-line-r

http://support.rstudio.org/help/discussions/questions/204-r-libpaths-difference-between-rstudio-and-command-line-r

Hi there,

你好,

Yes, we have a custom R_LIBS_USER setting which is intended to make it easier to upgrade the server to a new version of R without requiring that every user rename their library directory and/or re-build their packages. That way the administrator can do an upgrade without fearing that they'll break their user's working environment (realize that this could also be accomplished by writing an upgrade script that does the requisite rename/rebuild for each user).

是的,我们有一个定制的R_LIBS_USER设置,目的是使服务器升级到新的R版本更容易,而不需要每个用户重命名它们的库目录和/或重新构建它们的包。这样,管理员就可以进行升级,而不必担心会破坏用户的工作环境(还可以编写一个升级脚本,对每个用户进行必要的重命名/重新构建)。

Fully agree that this isn't necessarily desirable in all cases. Here is what you can do to work around it:

完全同意这并不是所有情况下都需要的。下面是你可以做的工作:

The Rtudio Server R_LIBS_USER is controlled by the following setting in /etc/rstudio/rsession.conf:

Rtudio服务器R_LIBS_USER由/etc/rstudio/rsession.conf中的以下设置控制:

r-libs-user=~/R/library

This variable supports the same wildcarding as R_LIBS_USER (as described here: http://stat.ethz.ch/R-manual/R-patched/library/base/html/libPaths.html) so you could change this to the following to make RStudio behave just like console R:

这个变量支持与R_LIBS_USER相同的通配符(如这里所述:http://stat.ethz.ch/R-manual/R-patched/library/base/html/libPaths.html),因此可以将其更改为以下,使RStudio的行为与控制台R类似:

r-libs-user=~/R/%p-library/%v

(note I believe that is the right syntax to reproduce the directory shown in your output above but you'll definitely want to double check that)

(注意,我认为这是复制上面输出中所示目录的正确语法,但您肯定需要再次检查)

Hope that clears things up and that you can get things configured as you'd like. Let us know if you have other questions or if this doesn't work as described.

希望你能把事情弄清楚,并希望你能按照自己的意愿进行配置。如果你有其他问题,或者不像描述的那样工作,请告诉我们。

J.J.

J.J.

#1


6  

A quick googling got me here:

我用谷歌搜索了一下:

http://support.rstudio.org/help/discussions/problems/868-how-to-configure-libpaths

http://support.rstudio.org/help/discussions/problems/868-how-to-configure-libpaths

so it looks like RStudio uses its own libs, set in /etc/rstudio/rsession.conf. Why? Who knows.

因此,RStudio使用自己的libs,设置在/etc/rstudio/rsession.conf中。为什么?谁知道呢。

#2


7  

Direct answer from the source:

直接回答来源:

http://support.rstudio.org/help/discussions/questions/204-r-libpaths-difference-between-rstudio-and-command-line-r

http://support.rstudio.org/help/discussions/questions/204-r-libpaths-difference-between-rstudio-and-command-line-r

Hi there,

你好,

Yes, we have a custom R_LIBS_USER setting which is intended to make it easier to upgrade the server to a new version of R without requiring that every user rename their library directory and/or re-build their packages. That way the administrator can do an upgrade without fearing that they'll break their user's working environment (realize that this could also be accomplished by writing an upgrade script that does the requisite rename/rebuild for each user).

是的,我们有一个定制的R_LIBS_USER设置,目的是使服务器升级到新的R版本更容易,而不需要每个用户重命名它们的库目录和/或重新构建它们的包。这样,管理员就可以进行升级,而不必担心会破坏用户的工作环境(还可以编写一个升级脚本,对每个用户进行必要的重命名/重新构建)。

Fully agree that this isn't necessarily desirable in all cases. Here is what you can do to work around it:

完全同意这并不是所有情况下都需要的。下面是你可以做的工作:

The Rtudio Server R_LIBS_USER is controlled by the following setting in /etc/rstudio/rsession.conf:

Rtudio服务器R_LIBS_USER由/etc/rstudio/rsession.conf中的以下设置控制:

r-libs-user=~/R/library

This variable supports the same wildcarding as R_LIBS_USER (as described here: http://stat.ethz.ch/R-manual/R-patched/library/base/html/libPaths.html) so you could change this to the following to make RStudio behave just like console R:

这个变量支持与R_LIBS_USER相同的通配符(如这里所述:http://stat.ethz.ch/R-manual/R-patched/library/base/html/libPaths.html),因此可以将其更改为以下,使RStudio的行为与控制台R类似:

r-libs-user=~/R/%p-library/%v

(note I believe that is the right syntax to reproduce the directory shown in your output above but you'll definitely want to double check that)

(注意,我认为这是复制上面输出中所示目录的正确语法,但您肯定需要再次检查)

Hope that clears things up and that you can get things configured as you'd like. Let us know if you have other questions or if this doesn't work as described.

希望你能把事情弄清楚,并希望你能按照自己的意愿进行配置。如果你有其他问题,或者不像描述的那样工作,请告诉我们。

J.J.

J.J.