[R] tryCatch question
Stephen Tucker
brown_emu at yahoo.com
Fri Aug 15 00:49:01 CEST 2008
Hi Kevin,
I learned to use tryCatch() from this page:
http://www1.maths.lth.se/help/R/ExceptionHandlingInR/
Hope this helps,
ST
----- Original Message ----
From: Luke Tierney <luke at stat.uiowa.edu>
To: rkevinburton at charter.net
Cc: r-help at r-project.org
Sent: Thursday, August 14, 2008 8:59:35 AM
Subject: Re: [R] tryCatch question
Read the argment descriptions and Look at the examples in ?tryCatch.
The `expr' argument (i.e. the code to try) and the `finally' argument
are expressions that are evaluated (via standard lazy evaluation of
arguments). The error condition handlers, provided as the `...'
argument in errorClass = handler form(s), are functions of one argument,
the error condition. As in the examples I usualy use fuctions writen
in-line. There is no non-standard evaluation involved, so standard
scoping rules apply.
luke
On Thu, 14 Aug 2008, rkevinburton at charter.net wrote:
> I would like to use the 'tryCatch' function but am having a hard
time getting my head around it. In 'C' like languages
try/catch/finally means try a block of statements and if any throw
an error then do the statements in the catch block and then error or
not always do the staements in the finally block. In 'R' as best as
I can tell the block of staements in the try block is a single
function. Does this mean I need to construct a temporary function
that contains what I would have put in the try blck? Also in 'R' it
seems the 'finally' function (of 'tryCatch' most closely mimics the
catch block of 'C'. Right? A similar comment on the finally
function. Do I need to create a temporary function that contains the
staements that I normally would put in a 'C' like catch clause? If I
do need to create functions for the try and error conditions what is
the scope or enviironment that the functions are called under? The
'try' function is relatively straightforward but when an error
occurs what variable will I have access to?
>
> 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.
>
--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa Phone: 319-335-3386
Department of Statistics and Fax: 319-335-3017
Actuarial Science
241 Schaeffer Hall email: luke at stat.uiowa.edu
Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
______________________________________________
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.
More information about the R-help
mailing list