[R] resume on error

Sarah Goslee sarah.goslee at gmail.com
Mon Mar 12 12:24:17 CET 2012


On Mon, Mar 12, 2012 at 4:39 AM, Alaios <alaios at yahoo.com> wrote:
> Thanks a lot.
> How I can use try though for plots. There are times where the plot function will fail
>
>  pdf(file=filename, width=width)
>  try(plot_per_band(list(get(varlist[[k]])), i, j, l, datalabels=seq(1:length(varlist))))
> dev.off()
>
> the code above does not print anything.

That's a long way from a reproducible example.

What do you expect to happen if plot() fails? Assign the output of
try() to an object.
Check whether that object is of class "try-error" and if so, do
whatever you want
the failure case to be.

Sarah

> B.R
> Alex
>
>
>
> ________________________________
>  From: R. Michael Weylandt <michael.weylandt at gmail.com>
>
> Cc: R help <R-help at r-project.org>
> Sent: Sunday, March 11, 2012 12:56 AM
> Subject: Re: [R] resume on error
>
> ? try or ? tryCatch
>
> Michael
>
>
>> Dear all,
>> I would like to ask you how I can catch an error on R and then ask it to resume.
>>
>> For example I have a large for loop and I know for a small number inside that loop there will be errors. How I can ask in that case from R just to ignore it and return back to the loop?
>>
>> I would like to thank you in advance fro your help
>>
>> B.R
>> Ale
>>
-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list