Switching a conditional based on whether R session is interactive or not

Viewed 66

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

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

if(ISINTERACTIVE){
    a <- 10
    b <- 6
}else{
    args = commandArgs(trailingOnly = TRUE)
    a <- args[1]
    b <- args[2]
}
1 Answers
Related