[R] Remove warnings.

rkevinburton at charter.net rkevinburton at charter.net
Tue Oct 14 16:56:38 CEST 2008


The problem is that I am interested in all the warnings but after they have been reported using the 'warnings()' command I am no longer interested in those warnings but similar warnings (of the same type) may occur with subsequent invocations and I am interested in these "new" warnings not the ones that have been reported already. If 'warnings()' cleared out the warnings then it would be ideal for me.

Thank you.

Kevin
---- hadley wickham <h.wickham at gmail.com> wrote: 
> Why don't you just suppress the warning messages you are not interested in?
> 
> ?suppressWarnings
> 
> Hadley
> 
> 
> On Tue, Oct 14, 2008 at 7:59 AM,  <rkevinburton at charter.net> wrote:
> > I have a function that could possibly generate warnings in a loop. What I want is to report the warnings (warnings()) then clear out the last.warning object so that if there is a call without warnings I will not see the previous warning.
> > Some example code:
> >
> > generatewarning <- function(s)
> > {
> >        warning(s)
> > }
> >
> > loop <- function(f=TRUE)
> > {
> >    if(f)
> >    {
> >        for(.index in 1:10)
> >        {
> >                if(.index %% 2)
> >                {
> >                        generatewarning(sprintf("%d warning", .index))
> >                }
> >        }
> >     }
> > }
> >
> > loop()
> > warnings("TRUE")
> > loop(FALSE)
> > warnings("FALSE")
> > loop()
> > warnings("TRUE")
> >
> > Notice that the call to "warnings("FALSE")" still reports the warnings from the previousely generated warnings. I want to "clear" this set since it has already been reported. Is there a way to do this?
> >
> > Thank you.
> >
> > Kevin
> >
> > ______________________________________________
> > 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.
> >
> 
> 
> 
> -- 
> http://had.co.nz/



More information about the R-help mailing list