[R] stop() vs. error() ?
Liaw, Andy
andy_liaw at merck.com
Sat Mar 27 03:43:05 CET 2004
OK, I guess I'm dense (again?)...
Stop where, and do what? I don't know many languages, but I haven't seen
(or heard) any that allows stopping in the middle of a function and do
nothing. What's the poor user to do at that point?
The only thing I could think of is when the programmer is debugging code,
and browser() allows execution to stop at that point. Is that what Ivo is
looking for? It was, as far as I can see, not even implied in his original
message.
Andy
> From: Andrew Robinson [mailto:andrewr at uidaho.edu]
> Sent: Friday, March 26, 2004 8:25 PM
> To: Liaw, Andy
> Cc: r-help at stat.math.ethz.ch; 'ivo welch'
> Subject: Re: [R] stop() vs. error() ?
>
>
> Andy,
>
> I'm really not sure that he hasn't told us. All he wants to
> do is stop the
> process, without throwing an error. return() won't work if
> he's in a nested
> function, it will just send him up to the next level. For
> example, let's say
> he's in a loop and calling his function in the loop. If he detects a
> situation he wants to stop the whole program and report it.
> I think that
> return will just terminate the function, and the loop will continue.
>
> e.g.
>
>
> spend.time <- function(i) {
> if (i == 50) {
> return()
> }
> if (i == 75) {
> stop("Is this an error?")
> }
> }
>
>
> for(i in 1:100)
> spend.time(i)
>
> i
>
> Andrew
>
> On Friday 26 March 2004 16:41, Liaw, Andy wrote:
> > So you still have not told us what exactly what you are
> looking for. What
> > do you want some sort of stop() to do inside a function,
> that is neither an
> > error nor returning? Can you show an example in some other
> language that
> > has such a feature?
> >
> > Andy
> >
> > > From: ivo welch [mailto:ivo.welch at yale.edu]
> > >
> > > Hi jim: ahhh, but then the error messages are off for
> "real errors"
> > > that occur later.
> > >
> > > Hi pierre: a return() in a (2nd-level) function can be
> > > different from a
> > > stop(). one could argue about whether it should be possible
> > > to stop()
> > > in a function of course, without it being an error().
> > >
> > > regards,
> > >
> > > /iaw
> > >
> > > James MacDonald wrote:
> > > > And a closer examination of the help page would lead
> you to this:
> > > >
> > > > options(show.error.messages=FALSE)
> > > > stop()
> > > >
> > > > which is what I believe you want....
> > > >
> > > > Jim
> > >
> > > also From Pierre Kleiber:
> > >
> > > The thing is that functions don't really stop... they return.
> > > So what
> > > you want is return()
> > > Cheers, Pierre
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
>
> --
> Andrew Robinson Ph: 208 885 7115
> Department of Forest Resources Fa: 208 885 6226
> University of Idaho E : andrewr at uidaho.edu
> PO Box 441133 W :
> http://www.uidaho.edu/~andrewr
> Moscow ID 83843
> Or: http://www.biometrics.uidaho.edu
> No statement above necessarily represents my employer's opinion.
>
>
>
More information about the R-help
mailing list