Re: [R] How to say "if error"

From: Paul Chatfield <p.s.chatfield_at_reading.ac.uk>
Date: Thu, 24 Jun 2010 08:41:54 -0700 (PDT)

Thanks again Joris - you've been very helpful J  

From: Joris FA Meys [via R]
[mailto:ml-node+2267176-1824205151-120784_at_n4.nabble.com] Sent: 24 June 2010 16:40
To: Paul Chatfield
Subject: Re: How to say "if error"  

You could do that using the options, eg :

set.seed(1)

x <- rnorm(1:10) 
y <- letters[1:10] 
z <- rnorm(1:10) 

warn <-getOption("warn")
options(warn=2)
for (i in list(x,y,z)){
  cc <- try(mean(i), silent=T)
  if(is(cc,"try-error")) {next}
  print(cc)
}
options(warn=warn)

see ?options under "warn"

Cheers
Joris

On Thu, Jun 24, 2010 at 5:12 PM, Paul Chatfield <[hidden email]> wrote:

>
> On a similar issue, how can you detect a warning in a loop - e.g. the
> following gives a warning, so I'd like to set up code to recognise
that and
> then carry on in a loop
>
> x<-rnorm(2);y<-c(1,0)
> ff<-glm(y/23~x, family=binomial)
>
> so this would be incorporated into a loop that might be
>
> x<-rnorm(10);y<-rep(c(1,0),5)
> for (i in 1:10)
> {ee<-glm(y~x, family=binomial)
> ff<-glm(y/23~x, family=binomial)}
>
> from which I would recognise the warning in ff and not those in ee,
saving
> results from ee and not from ff. The last bit would be easy adding a
line
> if(there_is_a_warning_message) {newvector<-NA} else {use results} but
how do
> you detect the warning message?
>
> Thanks all for your feedback so far,
>
> Paul
> --
> View this message in context:
http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2267140.html <http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2267140.htm l?by-user=t>
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>

-- 
Joris Meys 
Statistical consultant 

Ghent University 
Faculty of Bioscience Engineering 
Department of Applied mathematics, biometrics and process control 

tel : +32 9 264 59 87 
[hidden email] 
------------------------------- 
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

______________________________________________ 
[hidden email] 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. 



________________________________

View message @
http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2267176.html

To unsubscribe from Re: How to say "if error", click here
< (link removed) 
NoYXRmaWVsZEByZWFkaW5nLmFjLnVrfDIyNjcxNDB8LTE4MjM2NDg5MTM=> . 

 


-- 
View this message in context: http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2267182.html
Sent from the R help mailing list archive at Nabble.com.

	[[alternative HTML version deleted]]

______________________________________________
R-help_at_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.
Received on Thu 24 Jun 2010 - 18:47:52 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 Jun 2010 - 19:00:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive