简体   繁体   English

doWithOneRestart出错

[英]Error in doWithOneRestart

I have a longer, complex code (>7000 lines) with many nested functions, each of them enclosed in a separate tryCatch. 我有一个更长,更复杂的代码(> 7000行),有许多嵌套函数,每个函数都包含在一个单独的tryCatch中。 The code works perfectly except for a "pseudo-error": 代码完美无缺,除了“伪错误”:

Error in doWithOneRestart(return(expr), restart): no function to return from, jumping to top level 

doWithOneRestart() is internal in R as an element of the tryCatch function. doWithOneRestart()作为tryCatch函数的一个元素在R中是内部的。 I call it "pseudo-error", because the tryCatch should lead to stop() if an error ocurrs and write the error message in a log file. 我称之为“伪错误”,因为如果错误出现并在日志文件中写入错误消息,tryCatch应该导致stop() Instead, this "error" is not stopping the program (actually not influencing it at all) and it is shown only on the console and not written into the log file. 相反,这个“错误”并没有停止程序(实际上根本没有影响它),它只在控制台上显示而不是写入日志文件。 Usual debugging procedures did not help, because the error is not reproducible (!): it may ocurr at different processing stages of the program. 通常的调试程序没有帮助,因为错误是不可重现的(!):它可能在程序的不同处理阶段发生。 Changing the warning options to 0 or -1 will not help. 将警告选项更改为0或-1将无济于事。

Since the program does the job, this error is not critical. 由于程序完成了这项工作,因此这个错误并不重要。 But I would like to understand what is happening. 但我想了解发生了什么。 Maybe someone has already experienced the same problem, or could come up with an original debugging strategy ... 也许有人已经遇到过同样的问题,或者可能想出一个原始的调试策略......

Update (28.10.2013): I found out where the problem came from. 更新(28.10.2013):我发现了问题的来源。 It's linked to a problem with java heap overflow (I was using the xlsx package to read Excel files). 它与java堆溢出的问题有关(我使用xlsx包来读取Excel文件)。 Among many other problems: although the connection to the Excel file is closed (definitely!), the system considers it as an unused connection (shown in traceback() ), tries to close it, but finds out it is already closed: you get the "pseudo-error" described above, and never exactly at the same moment (not reproducible). 在许多其他问题中:尽管与Excel文件的连接已关闭(当然!),系统将其视为未使用的连接(显示在traceback() ),尝试关闭它,但发现它已经关闭:你得到上面描述的“伪错误”,并且从不完全在同一时刻(不可再现)。 Using the garbage collector gc() at the right place solved the problem. 在正确的位置使用垃圾收集器gc()解决了这个问题。 The script is now running stable for several days. 该脚本现在运行稳定了好几天。

Advice from Peter Dalgaard on R-help . Peter Dalgaard 关于R-help的建议

The easiest way to get that message is to execute return() from the top level: 获取该消息的最简单方法是从顶层执行return():

return(1) 

You might be trying to return() from source() d file. 您可能正在尝试从source() d文件return() Or maybe source() ing something that was intended to be inside a function body (extraneous '}' characters can do that). 或者也许source()想要在函数体内部的东西(无关的'}'字符可以做到这一点)。


The usual debugging strategies should work: calling traceback() after the error, or setting options(error = recover) . 通常的调试策略应该有效:在错误后调用traceback()或设置options(error = recover)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM