简体   繁体   English

R区分批处理和交互模式

[英]R distinguishing between batch and interactive mode

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. 谢谢你的帮助。

You can use the interactive function. 您可以使用interactive功能。 For example, executing this from a terminal 例如,从终端执行此操作

Rscript -e 'cat(interactive())'

returned FALSE for me, while executing interactive() from my RStudio session returned TRUE . 对我来说返回FALSE ,而从我的RStudio会话执行interactive()返回TRUE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM