Check if R is running in RStudio

Sacha Epskamp picture Sacha Epskamp · Sep 12, 2012 · Viewed 20.3k times · Source

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.

Answer

krlmlr picture krlmlr · Jul 23, 2013

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.