设置:
问题:
我已经下载了以下R脚本 https://github.com/daleroberts/heston/blob/master/heston.r 然后我使用RPy2软件包通过Python反复调用了其中的一个函数.现在,对于我输入到R函数中的某些输入,R返回以下错误:
I have downloaded the following R script https://github.com/daleroberts/heston/blob/master/heston.r and I repeatedly call one of the functions in there via Python using the package RPy2. Now, for some of my inputs that I feed into the R function, R returns the following error:
rpy2.rinterface.RRuntimeError:集成错误(PIntegrand,lower =0,上层= Inf,lambda,vbar,eta ,:检测到舍入错误
rpy2.rinterface.RRuntimeError: Error in integrate(PIntegrand, lower = 0, upper = Inf, lambda, vbar, eta, : roundoff error was detected
如何在Python中捕获此RuntimeError?
How do I go about catching this RuntimeError in Python?
RRuntimeError
源自 Exception
,因此您应该能够像捕获任何异常一样捕获它其他例外.
The RRuntimeError
is derived from Exception
so you should be able to catch it as you would with any other exception.
try: # your code except rpy2.rinterface.RRuntimeError: # handle exception
在rpy2 v3.0及更高版本中, RRuntimeError
似乎已移至其他位置(请参见示例代码
In rpy2 v3.0 and above, RRuntimeError
seems to have been moved elsewhere (see example code from documentation) so you may need to use this instead:
try: # your code except rpy2.rinterface_lib.embedded.RRuntimeError: # handle exception
有关此内容的更多信息: https://docs.python.org/3/tutorial/errors.html#handling-exceptions
这篇关于如何在Python中捕获rpy2.rinterface.RRuntimeError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程技术网(www.editcode.net)!