中断r脚本?

发布于 2025-02-08 09:33:03 字数 536 浏览 2 评论 0原文

我已经看过这个问题需要时功能。但是我正在使用一个复杂的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼眸印温柔 2025-02-15 09:33:03

如果要停止脚本,请使用stop(这会引起错误)。

如果您可能想重新启动,但需要检查工作状态,请考虑浏览器

a <- 1 # Do stuff I'm confident about
b <- 2 # Stuff I need to check if worked

cat(b)
browser() # or stop("Some error message")

但是如果您不想在此下方运行的东西,则最好将其删除。

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

a <- 1 # Do stuff I'm confident about
b <- 2 # Stuff I need to check if worked

cat(b)
browser() # or stop("Some error message")

But if there is stuff you don't want to run below this, it's probably best to delete it.

梦巷 2025-02-15 09:33:03

尝试使用q 。 ]

但是,退出也将完全退出R。如果要在功能后返回r控制台以停止执行,则可以使用 stopifnot 有意丢弃错误。

Try using quit or q. ]

However, quit will also completely quit R. If you want to return to the R console after your function to stop execution, you can use stopifnot to purposefully throw an error.

迷路的信 2025-02-15 09:33:03

您可以将quit()与参数 save> save ='ask'ask'和type 'c'c'在控制台中。

a <- 1 # Do stuff I'm confident about
b <- 2 # Stuff I need to check if worked

cat(b)

quit(save='ask')

You might use quit() with argument save='ask' and type 'c' in console then.

a <- 1 # Do stuff I'm confident about
b <- 2 # Stuff I need to check if worked

cat(b)

quit(save='ask')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文