Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command to see 'R' path that RStudio is using

Tags:

linux

path

r

exec

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.

like image 629
Mike Williamson Avatar asked Nov 19 '15 07:11

Mike Williamson


People also ask

How do I find my R path?

If we want to check the current directory of the R script, we can use getwd( ) function. For getwd( ), no need to pass any parameters. If we run this function we will get the current working directory or current path of the R script. To change the current working directory we need to use a function called setwd( ).

Where is the file path in RStudio?

One of the great things about using RStudio Projects is that when you open a project it will automatically set your working directory to the appropriate location. You can check the file path of your working directory by looking at bar at the top of the Console pane.

How do I use RStudio command line?

When editing files in the RStudio editor, any selection (or the current line if nothing is selected) can be sent to the active terminal via Ctrl+Alt+Enter (also Cmd+Alt+Enter on the Mac). If a single-line was sent to the terminal the cursor will advance automatically to the next line, allowing single-stepping.


1 Answers

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

like image 181
Josh O'Brien Avatar answered Sep 22 '22 17:09

Josh O'Brien