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

查看:21
本文介绍了查看 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) -- '消防安全').相反,我想知道 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.)

这里有很多很好的讨论,有些是特定于操作系统的.我有一台 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")

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

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):

详情:

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

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

[...]

值:

给出 R 主目录或路径的字符串特定组件.通常组件都是子目录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天全站免登陆