Skip to content
Back to formatted view

Raw Message

Message-ID: <49CF2AD9.7090008@biostat.ku.dk>
Date: 2009-03-29T08:01:29Z
From: Peter Dalgaard
Subject: how to get all iterations if I meet NaN?
In-Reply-To: <20090329072756.M62393@ibms.sinica.edu.tw>

Nash wrote:
>> Uwe Ligges wrote:
>> Please read the question more carefully, the sin() example was used 
>> as a method that does not give an error but works as expected (just 
>> with the warning), but the question is how not to break the loop,
>>  and so my answer was "see ?try".
> 
> So,
> Do you have any solution about his problem ?
> 

Yes he does: Use try().

This may not be very specific, but neither was the original question. 
The poster didn't give an example that we could fix, only the sin() 
example that he wanted his own code to work _like_.

So to answer the question with working code, one first needs to invent a 
broken example. Perhaps something like

for(i in 2:-2) {
    x <- try(chol(as.matrix(i)))
    if(inherits(x,"try-error")) x <- NaN
    print(x)
}


-- 
    O__  ---- Peter Dalgaard             ?ster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907