[R] Finding the first value without warning in a loop
Andreas Wittmann
andreas_wittmann at gmx.de
Sun Dec 7 08:38:57 CET 2008
Dear R useRs,
with the following piece of code i try to find the first value which can
be calculated without warnings
`test` <- function(a)
{
repeat
{
## hide warnings
suppressWarnings(log(a))
if (exists("last.warning", envir = .GlobalEnv))
{
a <- a + 0.1
## clear existing warnings
rm("last.warning", envir = .GlobalEnv)
}
if(a > 5 || !exists("last.warning", envir = .GlobalEnv))
break
}
return(a)
}
if i run this with test(-3), i would expect a=0 as return value.
Is it also possible to hide warnings during my function, i guess i use
suppressWarnings in a wrong way here?
Thanks and best regards
Andreas
More information about the R-help
mailing list