How do you programmatically declare if you use Architect / StatET?

Different IDEs have their own quirks, so it’s sometimes useful to know which IDE you use to run R.

You can check if you are using RStudio by testing the RSTUDIO environment RSTUDIO .

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

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

You can check for Revolution R by checking the 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 performed if you use Architect or StatET?

The closest I found is that, by default, Architect adds the path to the 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" 

I don’t understand how to make a reliable cross-platform test from this. Can you find a better test?

+6
source share
1 answer

I did not find any really good tests, but there are some more signs of tuning by the architect.

First, it downloads a package called rj . We can verify this using

 "package:rj" %in% search() 

Secondly, it overrides the default graphics device (see getOption("device") ). This is an anonymous function, so we cannot test by name, but I think the value of the name argument should distinguish it from other devices such as windows or png .

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

The combination of these two tests should be accurate enough to verify that the Architect is working.

 is_architect <- function() { "package:rj" %in% search() && !is.null(device_name <- formals(getOption("device"))$name) && device_name == "rj.gd" } 
+4
source

Source: https://habr.com/ru/post/978934/


All Articles