Re: [R] How to *completely* stop a script after stop()?

From: Duncan Murdoch <murdoch.duncan_at_gmail.com>
Date: Fri, 08 Apr 2011 12:57:06 -0400

On 08/04/2011 12:40 PM, William Dunlap wrote:
> Put an open brace in the first line of your file
> and a close brace in the last line.

This shares an advantage with the method I suggested: if there's a syntax error somewhere in the script, *nothing* will be executed. It has the disadvantage of not intermixing input and output the way the usual cut and paste would do.

Using source("clipboard", echo=TRUE) has a few disadvantages too:

It's nearly trivial to fix the first of these (make Ctrl-R do this instead); the 2nd one looks harder.

Duncan Murdoch

> I encourage people with scripts long enough that this
> is a problem to divide up their work into functions
> that a shorter script calls. (This is akin to UCSD
> Pascal on the Osbourne II that refused to deal with
> a function that could not fit onto the tiny screen
> -- it forced you do divide things up into small
> understandable chunks of work.)
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
> > -----Original Message-----
> > From: r-help-bounces_at_r-project.org
> > [mailto:r-help-bounces_at_r-project.org] On Behalf Of algorimancer
> > Sent: Friday, April 08, 2011 8:47 AM
> > To: r-help_at_r-project.org
> > Subject: Re: [R] How to *completely* stop a script after stop()?
> >
> > I too am encountering this problem. When I have a large
> > script, if I select
> > all in the editor and then ctrl-r to run, if it encounters a
> > stop() function
> > it simply prints an error message and continues to execute
> > the remainder of
> > the script, as opposed to terminating execution at that line.
> > The quit()
> > function exits R altogether, which I don't want. Yes, I
> > could manually
> > select only the portion of script which I want to run, but for lengthy
> > scripts which I run repeatedly (generally changing only the
> > name of the file
> > I want analyzed), this can be quite tedious. It appears that the only
> > solution is to put most of the code in a separate file and
> > call it using
> > source(); this has the downside of reducing the clarity of
> > the code -- it's
> > a sort-of structural spaghetti code approach.
> >
> > --
> > View this message in context:
> > http://r.789695.n4.nabble.com/How-to-completely-stop-a-script-
> > after-stop-tp3218808p3436704.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > R-help_at_r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 08 Apr 2011 - 16:59:37 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 08 Apr 2011 - 18:00:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive