I have written a function which reads data from files using read.delim ().
The names of these files are complicated and are built using arguments
to the wrapper function.  Since the files in question may or may not
exist, I thought to enclose the read.delim() call in a try():

        file <- <complicated expression>
        temp <- try(read.delim(file))
        if(inherits(temp,"try-error")) {
                (Do something)
        } else {
                (Do something else)
        }

But this doesn't work.  If file doesn't exist, then I get an error,
and the wrapper function terminates, despite the presence of the try().
The object ``temp'' never gets created.

I can of course easily get around the problem by testing with

        file.exists(file)

I just wondered --- why isn't try() working as expected here? Am I being silly to expect it to work? If so, what am I not understanding about try()?

Thanks for any insights.

        cheers,

                Rolf

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

______________________________________________
R-help@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.

Reply via email to