inst/testme/test-progressify-unwrap.R

#' @tags pkg-base
library(progressify)

options(progressify.debug = TRUE)

xs <- list(aa = 1, bb = 1:2, cc = 1:10)

message("*** withCallingHandlers(lapply(...), ...) |> progressify()")
warnings <- list()
y <- withCallingHandlers(
  lapply(xs, FUN = function(x) {
    if (length(x) == 2) warning("boom")
    sum(x)
  }),
  warning = function(w) {
    warnings <<- c(warnings, list(w))
    invokeRestart("muffleWarning")
  }
) |> progressify()
str(y)
str(warnings)
stopifnot(
  identical(y, lapply(xs, FUN = sum)),
  length(warnings) == 1L,
  conditionMessage(warnings[[1]]) == "boom"
)

expr <- quote(withCallingHandlers(lapply(xs, FUN = sum), warning = identity))
expr_t <- progressify(expr, substitute = FALSE, eval = FALSE)
print(expr_t)
stopifnot(identical(expr_t[[1]], as.name("withCallingHandlers")))


message("*** progressify() on a non-call gives an informative error")
exprs <- list(
  quote({ }),
  quote(local({ })),
  quote(( 42 ))
)
for (expr in exprs) {
  print(expr)
  res <- tryCatch({
    progressify(expr, substitute = FALSE, eval = FALSE)
  }, error = identity)
  print(res)
  stopifnot(
    inherits(res, "error"),
    grepl("because it is not a function call", conditionMessage(res))
  )
}

Try the progressify package in your browser

Any scripts or data that you put into this service are public.

progressify documentation built on Nov. 23, 2026, 9:08 a.m.