我想在我的代码中有一个条件,该条件使我可以区分代码是在批处理还是交互模式下运行(通过控制台)。就像这样:

if (interactive mode) {do this} else if (Batch mode) {do that}


有没有办法做到这一点?
谢谢你的帮助。

最佳答案

您可以使用interactive功能。例如,从终端执行

Rscript -e 'cat(interactive())'


为我返回了FALSE,而在我的RStudio会话中执行interactive()时返回了TRUE

07-24 09:52