[R] handling a cancelled file.choose()

From: Ben Tupper <btupper_at_bigelow.org>
Date: Wed, 06 Jun 2007 11:51:19 -0400


I have a file reading function that prompts the user with a file dialog if a filename is not provided in the argument list. It is desirable to return gracefully if the user selects "Cancel", but file.choose() throws an error instead of returning something like a character.

> file.choose()

[1] "/Users/ben/ben_idl.pref"

> file.choose()

Error in file.choose() : file choice cancelled

I naively planned to use nchar() to test the length, assuming cancellation would return a zero-length character. That appears to be out of the question. Are there other options available in the base package?


R-help_at_stat.math.ethz.ch 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. Received on Wed 06 Jun 2007 - 19:05:32 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 06 Jun 2007 - 20:33:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.