rstudio查询命令_查看RStudio使用的“ R”路径的命令

Original Question

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

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.

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

Edit & Answer

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"

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

which eventually resolves (2 symbolic links) to:

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

as the final destination.

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

解决方案

(Edited to reflect fact that this is apparently a Windows-specific solution.)

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

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:

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值