interactive()
This function returns TRUE when R is being used interactively and FALSE when not.
TRUE
FALSE
source
.First <- function() if(interactive()) x11()