查看RStudio使用的"R"路径的命令 [英] Command to see 'R' path that RStudio is using

查看:1098
本文介绍了查看RStudio使用的"R"路径的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎很容易,并且可能曾经被问过,但是我无法通过搜索找到它.

This seems easy and has likely been asked before, but I could not find it via a search.

我安装了几种R版本.我只是想知道,当我运行RStudio时,它指向的是哪种R风格.因此,我需要一个命令-理想情况下是在RStudio内-能告诉我当前正在使用的此RStudio窗口的基础R可执行文件.

I have a few flavors of R installed. I simply want to know, when I run RStudio, which flavor of R is it pointing to. So, I need a command -- within RStudio itself, ideally -- that can tell me the underlying R executable that is being used for this RStudio window that I am currently working with.

需要明确的是,我不需要/不想知道我正在使用的R的版本(例如R version 3.2.2 (2015-08-14) -- 'Fire Safety').相反,我想知道RStudio到达R的实际路径-在RStudio中查看它-这样我就可以知道"它使用的是哪个版本. (例如,/usr/local/bin/R.)

To be clear, I do not need / want to know the version of R that I'm using (e.g., R version 3.2.2 (2015-08-14) -- 'Fire Safety'). Instead, I want to know the actual path that RStudio is using to get to R -- looking at it from within RStudio -- so that I know "for reals" which version it's using. (E.g., /usr/local/bin/R.)

这里有很多精彩的讨论,有些是特定于OS的.我有一台Mac.就我而言,我发现:

There are a lot of great discussions here, and some are OS-specific. I have a Mac. In my case, I found that:

> 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,我会看到:

As those of you familiar can see, I am using brew. If I look for /usr/local/bin/R outside of R, I see:

$ 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个符号链接)解析为:

which eventually resolves (2 symbolic links) to:

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

作为最终目的地.

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

So on my system (Mac OS X), file.path(R.home("bin"), "R") was the most accurate.

推荐答案

(经过编辑,以反映这显然是Windows特定的解决方案.)

在Windows上,出于以下原因,我将使用以下内容: Henrik Bengtsson在这里讨论了一个长长的话题后,在这里进行了讨论.

Here on Windows, I'd use the following, for reasons discussed here by Henrik Bengtsson near the start of a long thread on the subject.

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

这比在help(R.home)的此代码段的值"部分中提到的几种设置中使用file.path(R.home(), "bin", "R")更好:

This is better than using file.path(R.home(), "bin", "R") in several settings alluded to in the "Value" section of this snippet from help(R.home):

详细信息:

Details:

R主目录是R的顶级目录 安装正在运行.

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

[...]

值:

给出R主目录或A路径的字符串 特定组件.通常,这些组件都是子目录 R主目录,但是在类Unix上可能不是这种情况 安装. [...]模块"的返回值以及在Windows上 "bin"是特定于子架构的位置.

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.

这篇关于查看RStudio使用的"R"路径的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆