[R] To Try or to TryCatch, I have tried to long

LCOG1 jroll at lcog.org
Tue Dec 6 18:11:16 CET 2011


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.



More information about the R-help mailing list