问题
I would like to have a condition in my code which allows me to distinguish if the code is running in Batch or interactive mode (via console). It would be something like this:
if (interactive mode) {do this} else if (Batch mode) {do that}
Is there a way to achieve this? Thanks for your help.
回答1:
You can use the interactive
function. For example, executing this from a terminal
Rscript -e 'cat(interactive())'
returned FALSE
for me, while executing interactive()
from my RStudio session returned TRUE
.
来源:https://stackoverflow.com/questions/28196406/r-distinguishing-between-batch-and-interactive-mode