[R-sig-eco] Function for continuing past stop error
Novack-Gottshall, Philip M.
pnovack-gottshall at ben.edu
Thu Jul 25 15:32:10 CEST 2013
Hi all,
I'm wondering if anyone knows of a function to continue after a
stop/error call in a loop. Something akin to next, but able to deal with
a stop-error.
I'm analyzing many samples, and some statistics/models can not be
applied to certain ones. The reasons why vary across samples, so it's
not as straightforward as adding a rule like "if sample size is < x, go
to next sample." It would be easier if there was a rule like "if the
following function results in an error, go to next sample." However, all
"stops" I know of permanently end the execution, and so adding a "next"
doesn't seem to work.
Here's a contrived example showing what I mean, which executes the first
two cases, but the third "stops", preventing execution for the fourth case:
library(MASS)
set.seed(314)
size <- c(10, 20, 1, 5)
for (i in 1:4) {
print(fitdistr(rnorm(size[i], mean=20), "gamma"))
}
# One solution would be to add a line like:
if(size[i] < 1) next
# But in my case, there would have to be many different such "next"
rules, and some I can't figure out exactly why an error is being produced
# Can anyone point me in a useful direction? I'm looking for something like:
if(error) next
Thanks,
Phil
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Phil Novack-Gottshall
Assistant Professor
Department of Biological Sciences
Benedictine University
5700 College Road
Lisle, IL 60532
pnovack-gottshall at ben.edu
Phone: 630-829-6514
Fax: 630-829-6547
Office: 332 Birck Hall
Lab: 107 Birck Hall
http://www1.ben.edu/faculty/pnovack-gottshall
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the R-sig-ecology
mailing list