Why does stop("we are done") print "Error in eval.with.vis(expr, envir, enclos) :" ? It would seem to me that a plain stop() is not an error, and that it would make more sense to have an error() function that is different from a stop(). Is there a rationale here that I am missing? sincerely, /iaw
Please do read the documentation of the functions you are trying to use. The description in ?stop says: 'stop' stops execution of the current expression and executes an error action. stop() is how error is flagged in R (and S in general). If that's not what you want, try something else. And the `something else' depends on what you want, which has not been described in detail. Andy> From: ivo welch > > Why does stop("we are done") print > "Error in eval.with.vis(expr, envir, enclos) :" ? > It would seem to me that a plain stop() is not an error, and that it > would make more sense to have an error() function that is > different from > a stop(). Is there a rationale here that I am missing? > > sincerely, /iaw > > ______________________________________________ > 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 > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}
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 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>>> ivo welch <ivo.welch at yale.edu> 03/26/04 02:23PM >>>hi andy: yes, I know what it does. My suggestion would be to have a different command, that is a "pure stop" without error condition (with its message). A stop and an error are really two different things. regards, /ivo Liaw, Andy wrote:> Please do read the documentation of the functions you are trying touse.> The description in ?stop says: > > 'stop' stops execution of the current expression and executesan> error action. > > stop() is how error is flagged in R (and S in general). If that'snot what> you want, try something else. And the `something else' depends onwhat you> want, which has not been described in detail. > > Andy ><snip> ______________________________________________ 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
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.... > > Jimalso From Pierre Kleiber: The thing is that functions don't really stop... they return. So what you want is return() Cheers, Pierre
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 > >
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. > > >
[I don't see any reason to keep this off-list. Apology to those bored by this thread.]> From: Andrew Robinson [mailto:andrewr at uidaho.edu] > > On Friday 26 March 2004 18:43, you wrote: > > OK, I guess I'm dense (again?)...I ain't kidding!> > Stop where, and do what? > > Stop where the condition is detected, and report which among > the plausible > conditions has been detected. > > > 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. > > He doesn't want to do nothing. He just doesn't want to throw > an error.So the intent is to jump all the way back to the R prompt? The only good reason for doing so, that my apparently not very good brain can think of, is when there's an error. What I learned in a programming class is that a program should have one and only one exit point. I.e., if f() calls g(), it's not desirable to have g() terminating the execution, but rather to have g() return a value that f() can check for. Of course, this can get tedious if you have f() calling g(), g() calling h(), etc., but it should make the code easier to maintain down the road. Having this behavior will also lead to confusion. Consider this scenario: Suppose I write a function f() that uses the Stop() and place it in a package, and upload to CRAN. Some poor soul downloads the package (actually believing that it'll do something useful), and try something like: result <- apply(x, 1, f, ...) and somehow trigger the Stop() inside f(). There's no error raised. What should the user expect? I can just see the poor R core fuming over the bug reports for apply() not returning something it promised to in ?apply...> > What's the poor user to do at that point? > > RTFM, just like at every other point.If you would be so kind as to as advise which FM to R, I'd be more than happy to do so. I'm very serious. Best, Andy> Andrew > -- > 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. > > >
hi andy: mea culpa. it is the exit function in most other languages. It would be exit(0) invocation in C (C++) and perl, for example. regards, /iaw 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 > > >