[R] Completely ignoring an error in a function...

Pieter Schoonees schoonees at ese.eur.nl
Thu Oct 18 02:15:23 CEST 2012


Have a look at example(try) and demo(error.catching)

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Jonathan Greenberg
> Sent: Wednesday, October 17, 2012 21:48
> To: r-help
> Subject: [R] Completely ignoring an error in a function...
> 
> The code base is a bit too complicated to paste in here, but the gist of my
> question is this: given I have a function
> 
> myfunction <- function(x)
> {
> # Do something A
> # Do something B
> # Do something C
> }
> 
> Say "#Do something B" returns this error:
> Error in cat(list(...), file, sep, fill, labels, append) :
>   argument 2 (type 'list') cannot be handled by 'cat'
> 
> A standard function would stop here.  HOWEVER, I want, in this odd case, to
> say "keep going" to my function and have it proceeed to # Do something C.
>  How do I accomplish this?  I thought suppressWarnings() would do it but it
> doesn't appear to.
> 
> Assume that debugging "Do something B" is out of the question.  Why am I
> doing this?  Because in my odd case, "Do something B" actually does what I
> needed it to, but returned an error that is irrelevant to my special case (it
> creates two files, failing on the second of the two files -- but the first file it
> creates is what I wanted and there is no current way to create that single file
> on its own without a lot of additional coding).
> 
> --j
> 
> --
> Jonathan A. Greenberg, PhD
> Assistant Professor
> Department of Geography and Geographic Information Science University of
> Illinois at Urbana-Champaign
> 607 South Mathews Avenue, MC 150
> Urbana, IL 61801
> Phone: 217-300-1924
> AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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