6

Different IDEs have quirks, and so it's occasionally useful to be able to know what IDE you are using to run R.

You can test if you are running RStudio by testing for the RSTUDIO environment variable.

is_rstudio <- function()
{
  env <- Sys.getenv("RSTUDIO")
  !is.null(env) && env == "1"
}

(Or, as Hadley commented, gui <- .Platform$GUI; !is.null(gui) && gui == "RStudio".)

You can test for Revolution R by check for a list named Revo.version in the base environment.

is_revo_r <- function()
{
  exists("Revo.version", "package:base", inherits = FALSE) && is.list(Revo.version)
}

Is there a similar check that can be done to see if you are running Architect or StatET?

The closest thing I've found is that by default Architect prepends the path to its embedded copy of Rtools to the PATH environment variable.

strsplit(Sys.getenv("PATH"), ";")[[1]][1]
## [1] "D:\\Program Files\\Architect\\plugins\\eu.openanalytics.architect.rtools.win32.win32_0.9.3.201307232256\\rtools\\bin"

It isn't clear to me how to make a reliable cross-platform test out of this. Can you find a better test?

Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
  • Update: These check functions are now in the devel version of `assertive`, which you can get via `library(devtools); install_bitbucket("assertive", "richierocks")`. – Richie Cotton Dec 01 '14 at 13:11
  • 1
    A bet way to check for RStudio is `.Platform$GUI` – hadley Dec 01 '14 at 14:02

1 Answers1

4

I haven't found any really nice tests, but there are a couple more signs of tweaking by Architect.

Firstly, it loads a package named rj. We can test for this using

"package:rj" %in% search()

Secondly, it overrides the default graphics device (take a look at getOption("device")). This is an anonymous function, so we can't test by name, but I think the value of the name argument should distinguish it from other devices like windows or png.

device_name <- formals(getOption("device"))$name
!is.null(device_name) && device_name == "rj.gd"

Combining these two tests should be reasonably accurate for checking if you are running Architect.

is_architect <- function()
{
  "package:rj" %in% search() &&
  !is.null(device_name <- formals(getOption("device"))$name) &&
  device_name == "rj.gd"
}
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360