[R] tryCatch question

rkevinburton at charter.net rkevinburton at charter.net
Thu Aug 14 16:51:18 CEST 2008


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



More information about the R-help mailing list