R-beta: why restart()
Simon Fear
fear at scmp.scm.liv.ac.uk
Thu Oct 23 17:35:44 CEST 1997
Martyn, you write
> I don't think restart() is necessary - it just seems like an invitation to
> bad programming to me.
It's needed when comparing, say, the time to convergence (if at all) of various
iterative processes, for each of a few hundred simulated values. For example one
wants basically
function(data){
summary<-rep(NA,1000)
for(i in 1:1000){
results1<-prog1(data[i])
results2<-prog2(data[i])
.
.
.
summary[i] <- f(results1,results2,...)
}
summary
}
where prog1, say, can sometimes fail fatally, for certain data values. The
*object of the exercise* is to find out what values cause program i to crash but
program j to run ok.
One can use immediate assigns (in Splus - haven't tried in R cos this study
needs a restart() function!) so that at least results pre-crash are stored. But
I want to study cases where 90% of all the cases fail fatally; it would never
get off the ground.
I accept that if you know what will cause the fatal fail you can program in a
test for it --- sometimes. What about this one: likely fatal error due to
solve(mat,x) having nonsingular matrix. Yes, yes, check there aren't any zeros
on the diagonal of the SVD ... but mine are 512x512 matrices.
It isn't efficient programming to completely re-write solve (or indeed to
re-write any built-in) with it's built-in fatal return changed to an error
return, and it isn't efficient to run solve if you're going to do an explicit
SVD in the first place. It *is* efficient to call try(solve()) where try is
function(expr, first = T)
{
# return either the proper answer to expr or NA (length 1),
# with printed error message. See splus_break for a version
# that returns error message as structure.
#
# DO NOT USE THE 'first' ARGUMENT
restart(first)
if(first) {
first <- F
expr
}
else {
# get_last_message doesn't always get the error message ...
print(paste("ERROR:", .C("get_last_message",
"")[[1]]))
NA
}
}
Thanks to someone whose name I have lost for posting this one to s-news.
Then you also get try(parse()).
Actually, I agree that self-written functions shouldn't need try(), you should
build in error handling. It's the built-in functions that make me suggest
restart() is `necessary'. The built-ins have error handling, but not under my
control.
Simon Fear
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
More information about the R-help
mailing list