[R] keep information on the number of warnings
David Winsemius
dwinsemius at comcast.net
Mon Aug 4 18:48:19 CEST 2014
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
More information about the R-help
mailing list