Skip to content
Back to formatted view

Raw Message

Message-ID: <1228120862.6607.1.camel@R1-Thux>
Date: 2008-12-01T08:41:02Z
From: Bernardo Rangel Tura
Subject: how to ignore errors
In-Reply-To: <1F0886F8-543C-44BA-BD45-FC9221814DFC@sjtu.edu.cn>

On Mon, 2008-12-01 at 16:17 +0800, Jiang Peng wrote:
> Dear listers,
> 
>   Hi .
> 
>   I googled before I ask this question in case to avoid violating the  
> "list law". The question was proposed by somebody else but nobody  
> gives a proper solution.
> 
>   How to ignore errors in a R loop? I have a R source file ,namely,  
> test.r.
>   I ran a loop in a command line
> 
>   > for(i in 1 : 100 ) {source("test.r",echo =T ) }
> 
>   and I found that when test.r have some error the loop will stop, but  
> test.r is just stochastically wrong,i.e., sometimes it works well if  
> no bad values return.
>   I want to know how to ignore such errors and let the loop continue.
> 
> thanks in advance.
> _______________________
> 

Jiang Peng,

The default solution is using try command, something like this

for(i in 1 : 100 ) {
	try(source("test.r",echo =T ))
}

-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil