递归调用直到错误不再存在

时间:2014-02-04 13:20:10

标签: r recursion try-catch

递归调用一个函数,直到错误在运行时不再是错误,我想我是因为堆栈溢出而得到错误,我已经尝试但没有成功结束 NULL或错误,任何帮助,谢谢。

fetchData <- function() 
    {
        #withRestarts(invokeRestart("a"),a=function(){QueryTrueFX()}) #i have tried restart within error function though i get NULL only
        qtf <- tryCatch(QueryTrueFX(),warning = function(w) {},error = function(e) {QueryTrueFX()})
        if(is.null(qtf))
        {
          fetchData()  
        }
    }
    a<-fetchData()
    Error in file(con, "r") : all connections are in use
    Called from: eval(expr, envir, enclos)
    Error during wrapup: all connections are in use
    Error during wrapup: target context is not on the stack
    a=tryCatch(fetchData(), error=function(e) NULL )
    a
    NULL

0 个答案:

没有答案