Re: [R] Finding the first value without warning in a loop

2008-12-07 Thread Gabor Grothendieck
log(-1) is not an error in R bug it does generate a warning and a NaN result. If there is a warning then the statement that causes the warning and all remaining statements in the tryCatch are not executed. Instead the warning= function is invoked. On Sun, Dec 7, 2008 at 1:09 PM, David Winsemius

Re: [R] Finding the first value without warning in a loop

2008-12-07 Thread David Winsemius
Thanks for that. I am having some difficulty figuring out how it works. The help page tells me (I think) that "y<-log(x)" gets matched to expr. Am I correct in thinking that if either an error or warning is produced, that tryCatch silently returns (or ?) to the for loop, and only otherwi

Re: [R] Finding the first value without warning in a loop

2008-12-07 Thread Gabor Grothendieck
Try this: for (x in c(-2, 2, 4)) { tryCatch({ y <- log(x) xx <- x break }, warning = function(w) {}) } print(xx) # 2 On Sun, Dec 7, 2008 at 2:38 AM, Andreas Wittmann <[EMAIL PROTECTED]> wrote: > Dear R useRs, > > with the following

Re: [R] Finding the first value without warning in a loop

2008-12-07 Thread David Winsemius
Have you considered instead sending the warnings to someplace where it won't bother the user? If so then sink() might be useful. My reading of the help page suggests that your call to suppressWarnigs is storing any results outside the Global environment. This is what I came up with. It may

[R] Finding the first value without warning in a loop

2008-12-06 Thread Andreas Wittmann
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 exis