Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在R中退出(0)?_R_Exit - Fatal编程技术网

如何在R中退出(0)?

如何在R中退出(0)?,r,exit,R,Exit,我在RStudio中工作,当函数满足特定条件(例如按键)时,我需要从函数内部退出代码(但不是RStudio会话)。在C/C++中,我们使用exit(0)函数来实现这一点。在R中,如果我调用quit(),它会尝试为我关闭整个R会话,但我只需要停止从函数内部执行当前编码 也就是说,我正在寻找下面这样的函数,当用户输入“q”时,它将导致程序退出 f <- function() { if (readline("Press 'q' to exit the code: ") == 'q'

我在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
 }

f这是定制的退出功能,看看是否有帮助

exit <- function() {
  .Internal(.invokeRestart(list(NULL, NULL), NULL))
                   }    
f <- function() {  
        if (readline("Press 'q' to exit the code: ") == 'q') 
           exit()

        return (1)
                }

exit这是定制的退出功能,看看是否有帮助

exit <- function() {
  .Internal(.invokeRestart(list(NULL, NULL), NULL))
                   }    
f <- function() {  
        if (readline("Press 'q' to exit the code: ") == 'q') 
           exit()

        return (1)
                }

退出这就是你要找的吗?您是否希望结束R会话?如果是这样,那么quit()/q()就是答案:这就是你想要的吗?您是否希望结束R会话?如果是这样,那么quit()/q()就是答案:漂亮第一个选择正是我所需要的它很好地关闭了执行,没有强迫我进入调试模式,也没有要求我关闭整个RStudio会话。如果它有效,请向上投票。Cheers使用R3.5.1Beautiful!时,退出功能为我生成非零退出第一个选择正是我所需要的它很好地关闭了执行,没有强迫我进入调试模式,也没有要求我关闭整个RStudio会话。如果它有效,请向上投票。Cheers使用R3.5.1时,
exit
函数为我生成非零退出
         f <- function() {  
        if (readline("Press 'q' to exit the code: ") == 'q') 
                     try{x=0/0}catch{}
          return (1)
        }