中断r脚本?
我已经看过这个问题需要时功能。但是我正在使用一个复杂的R脚本,我正在调试。我在vscode中运行它,如果有一个命令简单地停止完全运行脚本,那将是很好的,因为在Python中使用exit(1)
。例如,请参见下面的代码。
rm(list=ls()) # Ensuring workspace starts off clean
a <- 1 # Do stuff I'm confident about
b <- 2 # Stuff I need to check if worked
cat(b)
Function_to_Stop_Execution_Here() # What can I for about this?
Stuff_I_dont_want_to_run()
I've seen this question which answers how to exit a function when needed. But I'm working with a complex R script which I'm debugging. I run it in VScode, and would be nice if there was a command to simply stop running the script altogether, as using exit(1)
in python. See the code below for example.
rm(list=ls()) # Ensuring workspace starts off clean
a <- 1 # Do stuff I'm confident about
b <- 2 # Stuff I need to check if worked
cat(b)
Function_to_Stop_Execution_Here() # What can I for about this?
Stuff_I_dont_want_to_run()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果要停止脚本,请使用
stop
(这会引起错误)。如果您可能想重新启动,但需要检查工作状态,请考虑
浏览器
,但是如果您不想在此下方运行的东西,则最好将其删除。
If you want to stop a script, use
stop
(which raises an error).If you possibly want to restart, but need to examine the working state, consider
browser
But if there is stuff you don't want to run below this, it's probably best to delete it.
尝试使用或
q
。 ]但是,
退出
也将完全退出R。如果要在功能后返回r控制台以停止执行,则可以使用stopifnot
有意丢弃错误。Try using
quit
orq
. ]However,
quit
will also completely quit R. If you want to return to the R console after your function to stop execution, you can usestopifnot
to purposefully throw an error.您可以将
quit()
与参数 save> save ='ask'ask'和type'c'c'
在控制台中。You might use
quit()
with argumentsave='ask'
and type'c'
in console then.