【发布时间】:2017-06-24 01:42:37
【问题描述】:
我在 RStudio 工作,我需要从函数内部退出我的代码(但不是 RStudio 会话),当它满足特定条件时,例如一个按键。在 C/c++ 中,我们使用 exit(0) 函数来做到这一点。在 R 中,如果我调用 quit(),它会尝试为我关闭整个 R 会话,但我只需要从我的函数内部停止执行当前编码。
即我正在寻找如下功能,当用户输入“q”时,它会导致程序退出。
f <- function() {
if (readline("Press 'q' to exit the code: ") == 'q')
#I want to terminate the execution of program here
else
#continue the execution of other set of commands
}
帮我实现这个目标
【问题讨论】:
-
您要结束 R 会话吗?如果是这样,quit()/q() 就是答案:stat.ethz.ch/R-manual/R-devel/library/base/html/quit.html