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.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no "running inside RStudio". RStudio is merely an IDE layer that wraps around R; at the end of the day it just launches the normal R executable you need to have on your $PATH anyway to operate RStudio.
As a proxy, and as R Studio You could test available.packages() for the ‘manipulate’ package though, or as a shorter version see if RStudio added itself to the
.libPaths()content:Edit in May 2020 or eight years later The question does come up, and one can query a variety of things from within. Here is an example from the terminal of RStudio:
Similarly, from within the R session:
Edit in Aug 2021 or nine years later As all the answers listed here in the different answer may still be too much for people, you can also install package
rstudioapifrom CRAN and then ask it viarstudioapi::isAvailable()which comes backTRUEfor me inside RStudio andFALSEin ESS / standard R.