R区分批处理和交互模式 [英] R distinguishing between batch and interactive mode

查看:76
本文介绍了R区分批处理和交互模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

您可以使用interactive函数.例如,从终端

You can use the interactive function. For example, executing this from a terminal

Rscript -e 'cat(interactive())'

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

returned FALSE for me, while executing interactive() from my RStudio session returned TRUE.

这篇关于R区分批处理和交互模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆