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.
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.
To run the entire document press the Ctrl+Shift+Enter key (or use the Source toolbar button).
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.
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).
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With