Toggle conditional expression based on whether the R session is interactive or not

Does R have an environmental or global variable that I can use to switch between interactive and non-interactive versions of my code? This is important because it does not appear that there is a way for an interactive session to accept command line arguments. The corresponding question is asked here  but this does not concern my question.

An example of what I'm looking for looks something like this:

if(ISINTERACTIVE){
    a <- 10
    b <- 6
}else{
    args = commandArgs(trailingOnly = TRUE)
    a <- args[1]
    b <- args[2]
}
+4
source share
1 answer

It?

if(base::interactive()){
        a <- 10
        b <- 6
    }else{
        args = commandArgs(trailingOnly = TRUE)
        a <- args[1]
        b <- args[2]
    }
+6
source

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


All Articles