Thomas Pujol
2007-Dec-14 22:10 UTC
[R] way to check if the evaluation of an expression returns an error?
Is there a recommended or "good" way to check if the evaluation of an expression returns an error? e.g. var(NA) I wish var(NA) to return NA or "err", or some other value, even a text-string, but not an error message. I am using a loop to load many samples of data and to perform analysis on each sample. On occasion, the function I execute returns an error message. (e.g. when all data is NA, etc). I wish for the loop to continue to execute, and to have the function return an NA or NULL rather then an error message. --------------------------------- [[alternative HTML version deleted]]
Andrew Robinson
2007-Dec-14 22:33 UTC
[R] way to check if the evaluation of an expression returns an error?
?try Cheers, Andrew On Fri, Dec 14, 2007 at 02:10:52PM -0800, Thomas Pujol wrote:> Is there a recommended or "good" way to check if the evaluation of an expression returns an error? > > e.g. > var(NA) > I wish var(NA) to return NA or "err", or some other value, even a text-string, but not an error message. > > > I am using a loop to load many samples of data and to perform analysis on each sample. On occasion, the function I execute returns an error message. (e.g. when all data is NA, etc). I wish for the loop to continue to execute, and to have the function return an NA or NULL rather then an error message. > > > > --------------------------------- > > [[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. > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean.-- Andrew Robinson Department of Mathematics and Statistics Tel: +61-3-8344-9763 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 http://www.ms.unimelb.edu.au/~andrewpr http://blogs.mbs.edu/fishing-in-the-bay/