Skip to content
Back to formatted view

Raw Message

Message-ID: <AD5B03FE-3CD8-4078-BB90-59BE78CBEEFB@comcast.net>
Date: 2014-08-04T16:48:19Z
From: David Winsemius
Subject: keep information on the number of warnings
In-Reply-To: <36A5FEF8-75C0-4A24-948E-3EAB707B37C6@gmail.com>

On Aug 4, 2014, at 9:24 AM, Luis Borda de Agua wrote:

> Dear David
> 
> Thank you very much for your reply. I?ve only seen it now.
> I tried length(warnings) and I got a strange result.
> 
> When I used 
> 
> lw <- length(warnings)
> print(lw)
> 
> I obtained lw=36 
> 
> however,  the number of warnings was 38 according to message to screen:
> 
> "There were 38 warnings (use warnings() to see them)"
> 
> (I?m listing the warning messages below.)
> 
> Why should these numbers be different?

I have just disproven my initial hypothesis that I formed upon reading the R code of `warnings` that it had to do with the environment in which the warning was generated:

> f <- function () { g(); warning ("outer warn") }
> g <- function() { warning("inner warn") }
> f()
Warning messages:
1: In g() : inner warn
2: In f() : outer warn
> warnings()
Warning messages:
1: In g() : inner warn
2: In f() : outer warn

So, I simply don't know (and you have provided no example to reproduce the issue). May I remind you to include context from earlier messages? Looking back at your first message the number 36 appears rather than 38. Perhaps the number of warning varies from run to run? You would wnat to compare the number from such a message to the output of length(warnings()) after the run rather than before it.

---------
>> I?m using R 3.1.0 in OS X 10.9.4 (Mavericks)
>> 
>> I?m running a function Y that calls a function X which occasionally generates a warning. 
>> Say that I call the function X 1000 times, and out of these 1000 times I get the following message:
>> 
>> "There were 36 warnings (use warnings() to see them)"
>> 
>> How can I store the number 36 in a variable in function Y?
>> 
>> In other words, how can I extract the information on the number of warnings generated?
> 
> length(warnings())

--------------------

David.

> 
> Thank you in advance, 
> 
> Lu?s
> 
>> warnings()
> Warning messages:
> 1: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 2: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 3: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 4: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 5: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 6: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 7: In stode(y, time, func, parms = parms, ...) :
>  error during factorisation of matrix (dgefa);         singular matrix
> 8: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 9: In stode(y, time, func, parms = parms, ...) :
>  error during factorisation of matrix (dgefa);         singular matrix
> 10: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 11: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 12: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 13: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 14: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 15: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 16: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 17: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 18: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 19: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 20: In stode(y, time, func, parms = parms, ...) :
>  error during factorisation of matrix (dgefa);         singular matrix
> 21: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 22: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 23: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 24: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 25: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 26: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 27: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 28: In stode(y, time, func, parms = parms, ...) :
>  error during factorisation of matrix (dgefa);         singular matrix
> 29: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 30: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 31: In stode(y, time, func, parms = parms, ...) :
>  error during factorisation of matrix (dgefa);         singular matrix
> 32: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 33: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 34: In stode(y, time, func, parms = parms, ...) :
>  error during factorisation of matrix (dgefa);         singular matrix
> 35: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 36: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 37: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 38: In stode(y, time, func, parms = parms, ...) : steady-state not reached
> 
> 
> 
> 
> 
> _______________________________
> Lu?s Borda de ?gua
> Centro de Biologia Ambiental
> Faculdade de Ci?ncias
> Universidade de Lisboa
> Edif?cio C2, 6? Piso, Sala 2.6.04/07 
> Campo Grande
> 1749-016 Lisboa, Portugal
> Tel: +351 21 750 00 00 (ext: 22607)
> Fax: +351 21 750 00 28
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA