I think the problem is that it's only a warning and not an error. result_<-list() for(i in 1:10){ if(inherits(try(sqrt(9-i),silent=TRUE),"try-error")){ #If sqrt fails cat('fail',i,'\n') result_[[i]]<-0 } else { #If sqrt succeeds cat('succeed',i,'\n') result_[[i]] <- 1 } } result_
On Tue, Dec 6, 2011 at 11:11 AM, LCOG1 <jr...@lcog.org> wrote: > So after about 4 hours struggling with Try and TryCatch I am throwing in > the > towel. I have a more complicated function that used logspline through > iterative distributions and at some point the logspline doesnt function > correctly for some subsets but is fine with others so I need to be able to > identify when the error occurs and stop curtailing the distribution and I > think this Try or TryCatch should do the trick but I think I am missing > something here. A simple example > > > result_<-list() > for(i in 1:10){ > if(inherits(try(sqrt(9-i),silent=TRUE),"try-error")){ > #If sqrt fails > result_[[i]]<-0 } else { > #If sqrt succeeds > result_[[i]] <- 1 } > } > > > I would expect this to fail only when i > 9 but succeeds each time. DO i > need to specify something different where "try-error" resides? Thanks guys > > Cheers, > Josh > > > -- > View this message in context: > http://r.789695.n4.nabble.com/To-Try-or-to-TryCatch-I-have-tried-to-long-tp4165578p4165578.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.