error handling in R
3
0
Entering edit mode
@kimpel-mark-w-727
Last seen 9.7 years ago
A function I am calling from within one of my functions occasionally returns an error (bug in the other function, not my fault). When this happens, I would like for the value of the function that is blowing up to be "NA". Instead, my whole function blows up. Is there a way I can do something like this? my.function(x) { if (is.error(function.someone.else(x))) {NA} else {function.someone.else(x)} } Unfortunately, R doesn't seem to provide for this "is.error" approach. Is there another answer? Thanks, Mark
• 594 views
ADD COMMENT
0
Entering edit mode
Jeff Gentry ★ 3.9k
@jeff-gentry-12
Last seen 9.7 years ago
> Unfortunately, R doesn't seem to provide for this "is.error" approach. > Is there another answer? Look at the function 'try()', which should allow you to do the sort of things that you would like.
ADD COMMENT
0
Entering edit mode
A.J. Rossini ▴ 810
@aj-rossini-209
Last seen 9.7 years ago
Look at the try() function. "Kimpel, Mark W" <mkimpel@iupui.edu> writes: > A function I am calling from within one of my functions occasionally > returns an error (bug in the other function, not my fault). When this > happens, I would like for the value of the function that is blowing up > to be "NA". Instead, my whole function blows up. > > Is there a way I can do something like this? > > my.function(x) > { > if (is.error(function.someone.else(x))) {NA} else > {function.someone.else(x)} > } > > Unfortunately, R doesn't seem to provide for this "is.error" approach. > Is there another answer? > > Thanks, > > Mark > > _______________________________________________ > Bioconductor mailing list > Bioconductor@stat.math.ethz.ch > https://www.stat.math.ethz.ch/mailman/listinfo/bioconductor > -- rossini@u.washington.edu http://www.analytics.washington.edu/ Biomedical and Health Informatics University of Washington Biostatistics, SCHARP/HVTN Fred Hutchinson Cancer Research Center UW (Tu/Th/F): 206-616-7630 FAX=206-543-3461 | Voicemail is unreliable FHCRC (M/W): 206-667-7025 FAX=206-667-4812 | use Email CONFIDENTIALITY NOTICE: This e-mail message and any attachme...{{dropped}}
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 1 day ago
United States
You might look at either ?try or ?tryCatch. An untested modification: my.function(x){ options(show.error.messages = FALSE) atmpt <- try(function.someone.else(x)) options(show.error.messages = TRUE) if(inherits(atmpt, "try-error")){ atmpt <- NA } } HTH, Jim James W. MacDonald Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623 >>> "Kimpel, Mark W" <mkimpel@iupui.edu> 05/10/04 03:11PM >>> A function I am calling from within one of my functions occasionally returns an error (bug in the other function, not my fault). When this happens, I would like for the value of the function that is blowing up to be "NA". Instead, my whole function blows up. Is there a way I can do something like this? my.function(x) { if (is.error(function.someone.else(x))) {NA} else {function.someone.else(x)} } Unfortunately, R doesn't seem to provide for this "is.error" approach. Is there another answer? Thanks, Mark _______________________________________________ Bioconductor mailing list Bioconductor@stat.math.ethz.ch https://www.stat.math.ethz.ch/mailman/listinfo/bioconductor
ADD COMMENT

Login before adding your answer.

Traffic: 562 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6