Skip to content
Prev 62070 / 63433 Next

capture error messages from loading shared objects

Careful; tryCatch() on non-error conditions will break out of what's
evaluated, e.g.

res <- tryCatch({
  cat("1\n")
  message("2")
  cat("3\n")
  42
}, message = identity)

will output '1' but not '3', because it returns as soon as the first
message() is called.

To "record" messages (same for warnings), use withCallingHandlers()
instead, e.g.

msgs <- list()
res <- withCallingHandlers({
  cat("1\n")
  message("2")
  cat("3\n")
  42
}, message = function(m) {
  msgs <<- c(msgs, list(m))
  invokeRestart("muffleMessage")
})

This will output '1', muffle '2', output '3', and return 42, and 'msgs' holds
[[1]]
<simpleMessage in message("2"): 2

/Henrik
On Tue, Nov 28, 2023 at 10:34?AM Bill Dunlap <williamwdunlap at gmail.com> wrote: