[R] Flushing (Reset) 'last.warning'
Tiago R Magalhães
tiago17 at gmail.com
Thu Dec 13 12:28:54 CET 2007
Dear members of the mailing list,
I want to fetch warnings() from a series of prop.test calls. I want to
get "none" if no warning is issued, and "warning" if there is a problem.
I have looked (and relooked) at options(warn) and warning(), warnings()
and 'last.warning' but to no avail. I am a biologist, so the "R language
areas" are hard to fully understand.
I cannot flush the warnings before each prop.test calls; hence if there
is no warning, instead of "" I get (obviously) the last.warning from the
previous call. I tried to remove 'last.warning' but it won't let me
(wisely…) touch the base environment.
Code below. And if anyone could give some pointers it would be great.
Thank you, kind list
###############
collect <- vector('character', 3)
vec.1 <- c(10,19); total.1 <- c(24,35)
vec.2 <- c(5,12); total.2 <- c(50,211)
prop.test(vec.1, total.1); collect[1] <- names(warnings())
prop.test(vec.2, total.2); collect[2] <- names(warnings())
prop.test(vec.1, total.1); collect[3] <- names(warnings())
collect
[1] ""
[2] "Chi-squared approximation may be incorrect"
[3] "Chi-squared approximation may be incorrect"
I wanted
[1] ""
[2] "Chi-squared approximation may be incorrect"
[3] ""
More information about the R-help
mailing list