Dear Adrian,
For consistency, you might want to put toreturn$value <- output$value inside of
if (capture) {}. In any event, it makes sense for me to wait for the modified
admisc::tryCatchWEM to find its way to CRAN rather than to maintain my own
version of the function.
Thanks for this,
John
Dear John,
The logical argument capture is already in production use by other
packages, but I think this is easily solved by:
if (!is.null(output$value) & output$visible) {
if (capture) {
toreturn$output <- capture.output(output$value)
}
toreturn$value <- output$value
}
so th
Dear Adrian,
Here's my slightly modified version of your function, which serves my purpose:
--- snip ---
tryCatchWEM <- function (expr, capture = TRUE) {
toreturn <- list()
output <- withVisible(withCallingHandlers(
tryCatch(expr,
error = function(e) {
Dear Rui,
Thanks for this. Simon referred to demo(error.catching), and Adrian's version
returns the printed representation of the result along with messages.
Best,
John
On 2021-12-03, 11:35 AM, "Rui Barradas" wrote:
Hello,
I remembered having seen a function tryCatch.W.E and after
On Fri, 3 Dec 2021 at 00:37, Fox, John wrote:
> Dear Henrik, Simon, and Adrian,
>
> As it turns out Adrian's admisc::tryCatchWEM() *almost* does what I want,
> which is both to capture all messages and the result of the expression
> (rather than the visible representation of the result). I was ea
Hello,
I remembered having seen a function tryCatch.W.E and after an online
search, found where.
It was in a R-Help post and in demo(error.catching). The question by
Marius Hofert [1] was answered, among others, by Martin Maechler [2]
which included the function tryCatch.W.E.
These posts ref
Interesting exchange of ideas.
A feature that should be included soon in the codebase to help in some
use-cases -- eg. handling thousand database connections on {L,W}AN.
Il Gio 2 Dic 2021, 23:38 Fox, John ha scritto:
> Dear Henrik, Simon, and Adrian,
>
> As it turns out Adrian's admisc::tryC
Dear Henrik, Simon, and Adrian,
As it turns out Adrian's admisc::tryCatchWEM() *almost* does what I want, which
is both to capture all messages and the result of the expression (rather than
the visible representation of the result). I was easily able to modify
tryCatchWEM() to return the result
Simon's suggestion with withCallingHandlers() is the correct way.
Also, note that if you use tryCatch() to catch warnings, you're
*interrupting* the evaluation of the expression of interest, e.g.
> res <- tryCatch({ message("hey"); warning("boom"); message("there"); 42 },
> warning = function(w)
Dear John,
I have a function in package admisc called tryCatchWEM (catches warnings,
errors and messages):
> tryCatchWEM(foo())
$warning
[1] "warning1" "warning2"
Hope this helps,
Adrian
On Thu, 2 Dec 2021 at 23:04, Fox, John wrote:
> Dear R-devel list members,
>
> Is it possible to capture m
Adapted from demo(error.catching):
> W=list()
> withCallingHandlers(foo(), warning=function(w) { W <<- c(W, list(w));
> invokeRestart("muffleWarning") })
> str(W)
List of 2
$ :List of 2
..$ message: chr "warning 1"
..$ call : language foo()
..- attr(*, "class")= chr [1:3] "simpleWarnin
11 matches
Mail list logo