R distinguishing between batch and interactive mode

浪尽此生 提交于 2019-12-23 18:52:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!