How do you tell programmatically if you are running Architect/StatET?
Asked Answered
T

1

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?

Technetium answered 1/12, 2014 at 9:41 Comment(2)
Update: These check functions are now in the devel version of assertive, which you can get via library(devtools); install_bitbucket("assertive", "richierocks").Technetium
A bet way to check for RStudio is .Platform$GUIStringed
T
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"
}
Technetium answered 1/12, 2014 at 9:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.