Skip to content
Back to formatted view

Raw Message

Message-ID: <493B7D91.7020309@gmx.de>
Date: 2008-12-07T07:38:57Z
From: Andreas Wittmann
Subject: Finding the first value without warning in a loop

Dear R useRs,

with the following piece of code i try to find the first value which can 
be calculated without warnings

`test` <- function(a)
{
  repeat
  {
    ## hide warnings
    suppressWarnings(log(a))

    if (exists("last.warning", envir = .GlobalEnv))
    {
      a <- a + 0.1
      ## clear existing warnings
      rm("last.warning", envir = .GlobalEnv)
    }
 
  if(a > 5 || !exists("last.warning", envir = .GlobalEnv))
    break
  }

  return(a)
}

if i run this with test(-3), i would expect a=0 as return value.
Is it also possible to hide warnings during my function, i guess i use
suppressWarnings in a wrong way here?

Thanks and best regards

Andreas