查看 RStudio 正在使用的 'R' 路径的命令

Command to see 'R' path that RStudio is using

原问题

这看起来很简单,之前可能有人问过,但我无法通过搜索找到它。


我安装了几种R。我只是想知道,当我 运行 RStudio 时,它指向 R 的哪种风格。所以,我需要一个命令 - 在 RStudio 本身内,理想情况下 - 它可以告诉我正在使用的底层 R 可执行文件,我目前正在使用的这个 RStudio window。


明确地说,我不需要/不想知道我正在使用的 R 的版本(例如,R version 3.2.2 (2015-08-14) -- 'Fire Safety')。相反,我想知道 RStudio 用来到达 R 的实际路径——从 RStudio 内部查看——这样我就知道 "for reals" 它正在使用哪个版本。 (例如,/usr/local/bin/R。)


编辑并回答

这里有很多很棒的讨论,有些是 OS 特定的。我有一个Mac。就我而言,我发现:

> system("type R")
R is /usr/local/bin/R

> R.home()
[1] "/usr/local/Cellar/r/3.2.2_1/R.framework/Resources"

> file.path(R.home("bin"), "R")
[1] "/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/bin/R"

如您所见,我正在使用 brew。如果我在 R 之外寻找 /usr/local/bin/R,我会看到:

$ ls -l /usr/local/bin/R
lrwxr-xr-x  1 mike  admin  25 Nov 14 17:31 /usr/local/bin/R -> ../Cellar/r/3.2.2_1/bin/R

最终解析(2 个符号链接)为:

/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/bin/R

作为最终目的地。

所以在我的系统上(Mac OS X),file.path(R.home("bin"), "R") 是最准确的.

(经过编辑以反映这显然是 Windows 特定的解决方案这一事实。)

在 Windows 上,出于 discussed here Henrik Bengtsson 的原因,我将在有关该主题的长线程开头附近使用以下内容。

file.path(R.home("bin"), "R")

这比在 help(R.home) 的 "Value" 部分提到的几个设置中使用 file.path(R.home(), "bin", "R") 更好:

Details:

The R home directory is the top-level directory of the R installation being run.

[...]

Value:

A character string giving the R home directory or path to a particular component. Normally the components are all subdirectories of the R home directory, but this may not be the case in a Unix-like installation. [...] The return value for "modules" and on Windows "bin" is to a sub-architecture-specific location.