We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tryn()
I like the name
tryn <- function(expr, n = 10, silent = TRUE) { e <- parent.frame() attempt <- 0 expr <- as.expression(substitute(expr)) while (inherits(res <- try(eval(expr, envir = e), silent = silent), "try-error")) { attempt <- attempt + 1 if (attempt == n) { cond <- attr(res, "condition") msg <- paste0( "tryn() failed: maximum attempts reached: ", attempt, "\n", "Error in ", as.character(as.expression(cond[["call"]])), " : ", cond[["message"]] ) stop(simpleError(msg)) } } res } foo <- function() stop("I added an error") tryn(n = 10, foo()) #> Error: tryn() failed: maximum attempts reached: 10 #> Error in foo() : I added an error
Created on 2022-01-15 by the reprex package (v2.0.1)
The text was updated successfully, but these errors were encountered:
Create tryn.R (#80)
26ea7a6
redoc (#80)
8b24153
Update NEWS.md (#80)
dc911e8
Successfully merging a pull request may close this issue.
I like the name
Created on 2022-01-15 by the reprex package (v2.0.1)
The text was updated successfully, but these errors were encountered: