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

R 递归调用直到错误不再存在,r,recursion,try-catch,R,Recursion,Try Catch,递归调用函数,直到错误在运行时不再是错误,我想我得到错误是因为堆栈溢出,我已经尝试过,但没有成功以NULL或error结束,任何帮助,谢谢 fetchData <- function() { #withRestarts(invokeRestart("a"),a=function(){QueryTrueFX()}) #i have tried restart within error function though i get NULL only q

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

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

fetchData我不知道
QueryTrueFX
做什么,但是从错误消息中,我假设捕获错误时文件连接没有关闭。另外,避免R中的递归。您试图解决的问题是什么?很可能你需要的是更多关于
(while!qtf){sleep(10);your_function->qtf;}
@Roland谢谢你的回复。@CarlWitthoft我一直在尝试internet连接,如果它在运行时突然中断。
系统(“在这里ping你的IP地址”)怎么样