From du@@@@dr|@n @end|ng |rom un|buc@ro  Thu Dec  2 22:52:36 2021
From: du@@@@dr|@n @end|ng |rom un|buc@ro (=?UTF-8?B?QWRyaWFuIER1yJlh?=)
Date: Thu, 2 Dec 2021 23:52:36 +0200
Subject: [Rd] capturing multiple warnings in tryCatch()
In-Reply-To: <E3B708C1-8E1D-41A0-842A-9C05D229B3DB@mcmaster.ca>
References: <E3B708C1-8E1D-41A0-842A-9C05D229B3DB@mcmaster.ca>
Message-ID: <CAJ=0CtCF3YAKkcUETBZHgCO6EaUxNkxDCWxYq7nq1Ua+f_5ubw@mail.gmail.com>

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 <jfox at mcmaster.ca> wrote:

> Dear R-devel list members,
>
> Is it possible to capture more than one warning message using tryCatch()?
> The answer may be in ?conditions, but, if it is, I can't locate it.
>
> For example, in the following only the first warning message is captured
> and reported:
>
> > foo <- function(){
> +   warning("warning 1")
> +   warning("warning 2")
> + }
>
> > foo()
> Warning messages:
> 1: In foo() : warning 1
> 2: In foo() : warning 2
>
> > bar <- function(){
> +   tryCatch(foo(), warning=function(w) print(w))
> + }
>
> > bar()
> <simpleWarning in foo(): warning 1>
>
> Is there a way to capture "warning 2" as well?
>
> Any help would be appreciated.
>
> John
>
> --
> John Fox, Professor Emeritus
> McMaster University
> Hamilton, Ontario, Canada
> Web: http://socserv.mcmaster.ca/jfox/
>
>
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>


-- 
Adrian Dusa
University of Bucharest
Romanian Social Data Archive
Soseaua Panduri nr. 90-92
050663 Bucharest sector 5
Romania
https://adriandusa.eu

	[[alternative HTML version deleted]]



[Rd] capturing multiple warnings in tryCatch()
=?UTF-8?B?QWRyaWFuIER1yJlh?=