Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

statet

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?

like image 956
Richie Cotton Avatar asked Dec 01 '14 09:12

Richie Cotton


1 Answers

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"
}
like image 161
Richie Cotton Avatar answered Nov 12 '22 00:11

Richie Cotton