%% Slides given at S-PLUS Users Conference, October 1997, by RMH.

\documentclass[12pt]{article}   %latex2e
\usepackage{slverb}              %latex2e
%\documentstyle[12pt]{article}   %latex 2.09

% Warning: do not compress blanks into tabs.
% It will destroy the spacing in the S functions in the Example environment.

%\newfont{\sltt}{cmsltt10 scaled\magstep3}    % load slant tt font Large
\newfont{\sltt}{cmsltt10 scaled\magstep5}   % load slant tt font Huge   %duplicate for Huge
\newfont{\slttH}{cmsltt10 scaled\magstep5}   % load slant tt font Huge
\newfont{\ttHuge}{cmtt12 scaled\magstep4}    % load tt font       Huge
\newfont{\itHuge}{cmti12 scaled\magstep4}    % load italic font   Huge

\newcommand{\LB}{{\tt\char'173}}        % \tt {
\newcommand{\RB}{{\tt\char'175}}        % \tt }
\newcommand{\BS}{{\tt\char'134}}        % \tt \
\newcommand{\HH}{{\tt\char'043}}        % \tt #
%\newcommand{\slLB}{{\sltt\char'173}}    % \sltt {
%\newcommand{\slRB}{{\sltt\char'175}}    % \sltt }
%\newcommand{\slBS}{{\sltt\char'134}}    % \sltt \
%\newcommand{\slHH}{{\sltt\char'043}}    % \sltt #
\newcommand{\slLBH}{{\slttH\char'173}}    % \slttH {
\newcommand{\slRBH}{{\slttH\char'175}}    % \slttH }
\newcommand{\slBSH}{{\slttH\char'134}}    % \slttH \
\newcommand{\slHHH}{{\slttH\char'043}}    % \slttH #
% These commands give the stated character in the correct font in LaTeX.
% Beware of spacing in the "Example" environment, where spaces are significant:
%         "\LB{}contents\RB" produces  "{contents}"
%         "\LB contents \RB" produces  "{ contents }"


\newcommand{\hlinefill}{\mbox{\rule{0pt}{1ex}}\hrulefill}


\pagestyle{empty}
\topskip -1in
\topmargin -1in
\textheight 7.5in
\raggedbottom

\textwidth 10in
\parindent 0in
\oddsidemargin  -.5in

\special{landscape}

\newcommand{\la}{{\rm\Huge$\leftarrow$}}

\newcommand{\mc}[1]{\multicolumn{2}{l}{#1}}
\newcommand{\marpar}[1]{\marginpar{\raggedright#1}}
\newcommand{\Twiddle}{$\sim$}

%10pt
%\newenvironment{exsf}{\begin{list}{}{\setlength{\leftmargin}{\parindent}}\item[]\small\sf}{\end{list}}

%12pt
%\newenvironment{exsf}{\begin{list}{}{\setlength{\leftmargin}{\parindent}}\item[]\small\sf\boldmath}{\end{list}}

%12pt Huge
\newenvironment{exsf}{\begin{list}{}{\setlength{\leftmargin}{\parindent}}\item[]\sf\boldmath}{\end{list}}

\newcommand{\s}[1]{\mbox{\protect\small\sf#1}}
\newcommand{\msf}[1]{\mbox{\tiny\sf #1}}
\newcommand{\msm}[1]{\mbox{\scriptsize$#1$}}

%\renewcommand{\topfraction}{1.}
%\renewcommand{\bottomfraction}{0.}
%\renewcommand{\textfraction}{0.}
%\renewcommand{\floatpagefraction}{1.}
%\renewcommand{\floatsep}{0pt}
%\renewcommand{\textfloatsep}{0pt}
%\setcounter{topnumber}{25}
%\setcounter{bottomnumber}{0}
%\setcounter{totalnumber}{25}

%\renewcommand{\dbltopfraction}{1.}
%\renewcommand{\dblfloatpagefraction}{1.}
%\renewcommand{\dblfloatsep}{0pt}
%\renewcommand{\dbltextfloatsep}{0pt}
%\setcounter{dbltopnumber}{25}

\newcommand{\shortspace}{
 \setlength{\topsep}{0in}
 \setlength{\itemsep}{0in}
 \setlength{\parsep}{0in}
 \setlength{\parskip}{0in}
}

\begin{document}
\Huge
\parskip=1ex


\begin{center}
\Huge
ESS-mode and S-Plus\\
Richard M. Heiberger\\[1ex]
based on joint work with\\
A.J. Rossini(U South Carolina),\\
 Kurt Hornik(TU-Wien), and Martin Maechler (ETHZ).\\[2ex]
Thanks also to\\
Doug Bates, Ed Kademan, Frank Ritter (initial versions),\\
and David Smith (3.x, 4.x)\\[3ex]

Richard M. Heiberger\\[.4ex]
Temple University\\[.4ex]
Philadelphia, PA 19122-2585\\[.4ex]
{\sf rmh@astro.ocis.temple.edu}\\[2ex]
S-PLUS Users Conference, Seattle, October 1997
\end{center}


\newpage
\begin{center}Abstract\end{center}
ESS [Emacs Speaks Statistics] (formerly S-mode) is a a GNU Emacs
package for running S(plus), R, X-LispStat, SAS and potentially other
interactive `statistical' languages in an `inferior' buffer, editing
source code in these languages and interacting with the running
program.  This talk will discuss the capabilities and advantages of
using ESS as the primary interface to Splus.


I am talking about the version which will be released in November 1997
as ESS-5.0.\\
\hspace*{2ex}{\sf http://franz.stat.wisc.edu/pub/ESS/ESS-5.0.tar.gz}\\
\hspace*{2ex}{\sf ftp://franz.stat.wisc.edu/pub/ESS/ESS-5.0.tar.gz}\\
The previous stable version was 4.8 in
{\sf S-mode-4.8.MM6.XE2.tar.gz}\\

\newpage

What is S-Plus

What is EMACS

What is ESS-mode

Why should I use ESS-mode with S-Plus

Other features in ESS-mode

\newpage
\begin{itemize}
\item
What is S-Plus?

The best, most expressive, most fun, most powerful environment and
program for designing methods for statistical analysis of data and for
displaying and analyzing data.

\newpage
\item
What is EMACS?

A text editor that is fully configurable and extensible, can work with
many files simultaneously, interacts with the computer operating
system and other executing processes, has language specific
customizations, and can indeed do anything (the previous edition
iconized to the Kitchen Sink).

In addition to S, Emacs has modes designed for \TeX, \LaTeX, fortran,
c, lisp, text, directories, telnet, rlogin, terminal emulators, nroff,
pascal, c++, ada, asm, etc.

Mode customizations include indentation patterns, syntactic
highlighting, comment structure, and interaction with the program that
uses the file as input.

\newpage
\item
What is ESS-mode?

A package written in emacs which is designed to work with Statistical
software.  The initial development under the name S-mode was designed
for S.  It has been extended to dialects of S (S-Plus, S4, R) and now
to other statistical packages (SAS, Xlispstat).  With the extension
came the name change to ESS-mode (Emacs Speaks Statistics).

There are three primary components to ESS
\begin{description}
\item [S-mode] for editing {\tt myfile.s} and submitting individual
lines and paragraphs of S code to the running S process.
\item [inferior-ess-mode]  for executing an S process inside an emacs buffer.
\item [S-transcript-mode] for reviewing and possibly re-executing the
transcript of a previous S process.
\end{description}


\item
Why should I use ESS-mode with S-Plus?

It will improve your productivity.


\newpage
{\bf S-mode.} Automatic syntactic indentation and highlighting of source
\vspace*{-.5ex}

{
\underline{\slttH \slHHH\slHHH as typed -- too long.  Line is folded}\\
            {\tt case0701 <- read.table(file={\slttH'case0701.asc'}, header\BS} \\
            {\tt =\underline{T})}\\
\vspace*{.0ex}

\underline{\slttH{\slHHH\slHHH insert line break, syntactic indentation lost}}\\
             \tt{case0701 <- read.table(file={\slttH'case0701.asc'},}\\
             \tt{header=\underline{T})}\\
\vspace*{.0ex}

\underline{\slttH{\slHHH\slHHH automatic indentation at right parenthesis level}}\\
             \tt{case0701 <- read.table(file={\slttH'case0701.asc'},}\\
        \tt\verb+                      header=+\underline{T})\\
\vspace*{.0ex}

Here by font, on a terminal by color.\\
\underline{\slttH{\slHHH\slHHH comments}}~~~~~~~{\rm underlined italic}\\
          {\slttH"quoted strings"}~{\rm italic}\\
\underline{keywords}~~~~~~~~~{\rm underlined}
}


\newpage
{\bf S-mode.} Fill-paragraph understands comments.
\vspace*{2ex}

Too long and folded.\\
\underline{\slttH\slHHH\slHHH~Sometimes statements are complicated with many}\BS\\
\underline{\slttH levels of}\\
\underline{\slttH\slHHH\slHHH~ parentheses.  ESS gets the indentation right.}
\vspace*{3ex}

Fill-paragraph broke lines evenly and generated the comment symbols.\\
\underline{\slttH\slHHH\slHHH~Sometimes statements are complicated with}\\
\underline{\slttH\slHHH\slHHH~many levels of parentheses.  ESS gets the}\\
\underline{\slttH\slHHH\slHHH~indentation right.}

\newpage
{\bf S-mode.} Detects unbalanced parentheses
\vspace*{2ex}

\underline{\slttH\slHHH\slHHH~Complicated statement}

{\ \tt if ((abs(end(x) + tspar(x)["deltat"] - start(y))}\\
{\ \tt \hspace*{3em}< eps)  \&\&}\\
{\ \tt \hspace*{2.5em}(frequency(x) == frequency(y)) \&\&}\\
{\ \tt \hspace*{2.5em}\fbox{\slttH(}(length(units(x))==0) ||}\\
{\ \tt \hspace*{3em}(length(units(y))==0) ||}\\
{\ \tt \hspace*{3em}(units(x) == units(y))\fbox{\slttH]})}
\vspace*{2ex}


On a color display screen the unbalanced parentheses are bright purple.


\vspace*{2ex}

Syntactic highlighting simplifies detection of unbalanced\\
quotation marks.

{\tt tmp <- f(x, {\slttH"this is a string, y, z)}}



\newpage

{\bf inferior-ess-mode.} Evaluating lines of S source

Program statements and function definitions
can be developed in an editing window that is
NOT the same as the executing S process.

The lines are sent to S with keyboard
commands.


\hlinefill
\begin{verbatim}

lm( y ~ x, data=mydata)
\end{verbatim}
\begin{slverbatim}
--**-Emacs: test.s   (ESS[S] [none])--L1--All------
\end{slverbatim}
\begin{verbatim}
> lm( y ~ x, data=mydata)
Error: Object "mydata" not found
Dumped

\end{verbatim}
\begin{slverbatim}
--**-Emacs: *S+3:1*  (iESS [S+3:1]: run)--L6--All--

\end{slverbatim}
\hlinefill


Errors are corrected in the editing window and resent.
\newpage
Errors are corrected in the editing window and resent.

\hlinefill

\begin{verbatim}

lm( y ~ x, data=myrealdata)
\end{verbatim}
\begin{slverbatim}
--**-Emacs: test.s   (ESS[S] [none])--L1--All------
\end{slverbatim}
\begin{verbatim}
> lm( y ~ x, data=mydata)
Error: Object "mydata" not found
Dumped
> lm( y ~ x, data=myrealdata)
\end{verbatim}
\begin{slverbatim}

--**-Emacs: *S+3:1*  (iESS [S+3:1]: run)--L6--All--
\end{slverbatim}
\hlinefill

The corrected {\tt test.s} is now a permanent record of the
commands that are needed.

This form of interaction between the editing process and the S
execution is usually the best way to develop a set of functions.

\newpage
{\bf inferior-ess-mode.}   The session file is always available.

The entire S session is in a buffer and can be be searched, edited,
reviewed, saved during the current session.  Previous results never
run off the top of the screen and are never subject to arbitrary line
restrictions.

The buffer containing the S session transcript can be saved as a file.
The file can be revisited later for editing into a report or handout.
The file can be brought back into a buffer in S-transcript-mode and used as
the base for further development.

\newpage
{\bf S-transcript-mode.}  The transcript of a previous S session can
be brought back and used as model for further development.  When the
cursor is placed on any line of a multi-line command, the entire
command can be sent over 
to any relevant active inferior S-process with a single keystroke.

\begin{verbatim}
> xyplot(data ~ voltage | power, data=time.powers,
+        scales=list(y=list(relation="free")),
+        ylab="powers of time",
+        main="case0802  ladder of powers")
>
\end{verbatim}

Once the command works correctly, it can be cleaned mechanically with
the {\tt ess-transcript-clean-region} function.

\begin{verbatim}
xyplot(data ~ voltage | power, data=time.powers,
       scales=list(y=list(relation="free")),
       ylab="powers of time",
       main="case0802  ladder of powers")
\end{verbatim}

\newpage
\item
Other features in ESS-mode

\begin{itemize}
\item Help files go to their own buffer.  Many can be viewed simultaneously.
\item Several different instantiations of the same or different dialects of S (or other
statistical program) can be controlled simultaneously through the same emacs process.
\item Multiple S source files can be developed simultaneously.
\item ESS-mode recognizes functions, multi-line statements,
highlighted regions, parenthetical expressions.
\item When an error is detected in a source file, ESS switches the display to the file and
places the cursor on the line where the error was detected.
\item Object-name-completion.
\item Menu access.
\end{itemize}

\end{itemize}
\end{document}


