-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of William Dunlap
Sent: Tuesday, December 06, 2011 11:38 AM
To: gleynes+r at gmail.com; ROLL Josh F
Cc: r-help at r-project.org
Subject: Re: [R] To Try or to TryCatch, I have tried to long
Look at the archives of this mailing list for a discussion entitled
'Stack trace?' on Nov 9-10 of this year.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Gene Leynes
Sent: Tuesday, December 06, 2011 10:58 AM
To: ROLL Josh F
Cc: r-help at r-project.org
Subject: Re: [R] To Try or to TryCatch, I have tried to long
I've had the same problem in other cases.
Does anyone know how to catch warnings as well as errors?
On Tue, Dec 6, 2011 at 12:34 PM, ROLL Josh F <JRoll at lcog.org> wrote:
**
Agreed. But what I am trying to control is when I get a warning.
I want to do something different if a warning OR an error pop up? Any ideas?
Cheers
------------------------------
*From:* gleynes at gmail.com [mailto:gleynes at gmail.com] *On Behalf Of
*Gene Leynes
*Sent:* Tuesday, December 06, 2011 10:27 AM
*To:* ROLL Josh F
*Cc:* r-help at r-project.org
*Subject:* Re: [R] To Try or to TryCatch, I have tried to long
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 <jroll at 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.