[S] Summary of braces { }

eric.gibson@pharma.Novartis.com
Thu, 22 Oct 1998 18:42:21 -0400


Dear colleagues,

Here's the original post, with replies from
Bill Dunlap and Chuck Taylor at Mathsoft
and Brian Ripley. They all give very useful
information. I'll try to give script windows a shot,
but I have been using the wordpad and pasting
since version 3.2 for windows and old habits die hard.

Thanks to all.
-Eric Gibson

ORIGINAL POST

A few days ago someone posted a "helpful hint"
that enclosing a block of commands in braces and then
pasting into the commands window results in faster processing.

i.e. pasting

function1( )
function2( )
function3( )

is slower than pasting

{function1( )
function2( )
function3( )}

I have also found this to be true and have been "bracing"
every block of code that I paste into the commands
window prior to pasting it.

Can someone explain why this is faster and whether or not
it is a good idea for me to be "bracing" everything prior
to pasting?

I operate in the windows NT environment and I use the
Wordpad as an editor, copying blocks of S code from it and
pasting them into the commands window.
I apologize if this is a dumb question with an obvious answer.
Perhaps someone can give me a page number to look at
in the Splus 4.0 manuals, or a page number in V&R (old edition).

Eric Gibson, Ph.D.
Novartis Pharmaceuticals
The opinions expressed herein are those of Eric Gibson and
in no way represent Novartis Pharmaceuticals.
eric.gibson@pharma.novartis.com

>From Bill Dunlap:

Splus does a fair bit of setup before and cleanup after each "top level
expression". After a top level expression it will write all changed
datasets to disk, notify the GUI about changes to datasets, free a bunch
of memory, decide whether to automatically print results (and print
them), and some other things. By combining several expressions into
one top level expression you save on this per-expression overhead.

You can go too far in this regard, as virtual memory requirements tend
to build up during a top level expression (e.g., those datasets waiting
to be written to disk take up memory).

You can also speed things up somewhat by writing functions to encapsulate
collections of expressions. Then temporary variables automatically
are deleted at the end of the function call and don't have to be written
to disk (and the GUI doesn't have to keep track of them).

---------------------------------------------------------------------------
-
Bill Dunlap 22461 Mt Vernon-Big Lake
Rd
Data Analysis Products Div. of MathSoft, Inc. Mount Vernon, WA 98274
bill@statsci.com 360-428-8146

"All statements in this message represent the opinions of the author and do
not necessarily reflect MathSoft policy or position."

>From Chuck Taylor:

An unsolicited recommendation: Try the script window in S-PLUS 4.x
instead of Wordpad. You can open a script window by selecting
File/New/Script File. Enter your text as usual. Then you can run either
the entire file or selected text with the Run button. The Run button is
the F10 key, or, equivalently, you can click on the icon that looks like a
solid triangle pointing to the right on the bottom line of the toolbar.
This saves cutting and pasting. File/Save then saves your file as text
(with a *.ssc suffix).

You can also open a script window to create a function (say "foo") by
typing Edit(foo).

Best regards,

Chuck

|-----------------------------------------------------------------------|
| Chuck Taylor Senior Quality Assurance Engineer |
| MathSoft Seattle, WA, USA chuck@statsci.com |
| |
| "All statements in this message represent the opinions of the author |
| and do not necessarily reflect official MathSoft policy or position." |
|-----------------------------------------------------------------------|

>From Brian Ripley:

You won't find it there, definitely not in V&R1, as it is a `feature' of
S-PLUS 4.x only which was not even released when V&R2 appeared. The
underlying reason appears to be that communication between the command line
and the S-PLUS engine in 4.x has very considerable overheads, and is done
an expression at a time. `Bracing' commands makes them into an expression.
Even pasting in a function assignment, e.g.

foo <- function(blah) {
.....
}

which is a single expression, seems very slow to me on 4.x. Perhaps
someone in MathSoft DAPD can explain how they managed to slow this down so
much from 3.3 to 4.0! (Not by as much as re-plotting on an existing
graph though.)

Is `bracing' a good idea? First, if any command fails, all the work is
lost, and because of this backout requirement, the memory requirements may
be much larger. Second, under the default setting of a graphsheet you will
get graphs on multiple pages, which may be what you want. Third,
grouping expressions does have advantages on any system, as the use of
grain.size in For() loops shows (that groups iterations into single
expressions).

The reason I know this is that the easiest way I find to work when
demonstrating with 4.5 is to have commands in a script window, highlight
them and submit them. That does submit them as a single expression. I
would think a script window is at least as useful an editor for S source as
Wordpad (if not as useful as ESS mode in NTemacs, since that gives syntax
highlighting). As a new feature, script windows are probably still highly
under-valued.

--
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

----------------------------------------------------------------------- This message was distributed by s-news@wubios.wustl.edu. To unsubscribe send e-mail to s-news-request@wubios.wustl.edu with the BODY of the message: unsubscribe s-news