4

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]
}
irritable_phd_syndrome
  • 4,631
  • 3
  • 32
  • 60

1 Answers1

6

This?

if(base::interactive()){
        a <- 10
        b <- 6
    }else{
        args = commandArgs(trailingOnly = TRUE)
        a <- args[1]
        b <- args[2]
    }
Carl Boneri
  • 2,632
  • 1
  • 13
  • 15