Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if R is running in RStudio

Tags:

r

rstudio

I am looking for a way to test if R is being run from RStudio. For some reason I could find the answer on google yesterday but not today, but I think it had to do with testing if a certain system variable was set.

like image 883
Sacha Epskamp Avatar asked Sep 12 '12 13:09

Sacha Epskamp


People also ask

How do I know if R is working?

If you are using a Windows PC, there are two ways you can check whether R is already installed on your computer: Check if there is an “R” icon on the desktop of the computer that you are using. If so, double-click on the “R” icon to start R. If you cannot find an “R” icon, try step 2 instead.

How do I run in R studio?

To run the entire document press the Ctrl+Shift+Enter key (or use the Source toolbar button).

Can R run in the background?

RStudio 1.2 introduced the ability to send long running R scripts to local and remote background jobs. This functionality can dramatically improve the productivity of data scientists and analysts using R since they can continue working in RStudio while jobs are running in the background.

Does R run line by line?

The R console is interactive, we can directly enter and execute commands here, or we write our script in the code editor and “Run” the script which will then be executed “line-by-line” in the R console (shown later).


2 Answers

This is from ?rstudio:

# Test whether running under RStudio  isRStudio <- Sys.getenv("RSTUDIO") == "1" 

There is also rstudioapi::isAvailable(), but checking this is not as reliable because RStudio doesn't seem to really need the rstudioapi package to work correctly.

like image 61
krlmlr Avatar answered Sep 28 '22 07:09

krlmlr


Check the .Platform$GUI option for "RStudio"

is.rstudio = function(){   .Platform$GUI == "RStudio" } 

See:

http://thecoatlessprofessor.com/programming/detecting-if-r-is-in-rstudio-and-changing-rstudios-default-graphing-device/

like image 24
coatless Avatar answered Sep 28 '22 08:09

coatless