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

Sarah Goslee sarah.goslee at gmail.com
Wed Oct 17 21:51:29 CEST 2012


I'd wrap it in try() - the failing function will run, and you can
check after the fact whether it failed or not.

Sarah

On Wed, Oct 17, 2012 at 3:48 PM, Jonathan Greenberg <jgrn at illinois.edu> wrote:
> 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


-- 
Sarah Goslee
http://www.functionaldiversity.org




More information about the R-help mailing list