~ubuntu-branches/ubuntu/natty/ess/natty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
%% $Id: ESS_intro.tex,v 1.2 1999/11/16 20:58:36 ess Exp $
%%
%% $Log: ESS_intro.tex,v $
%% Revision 1.2  1999/11/16 20:58:36  ess
%% Martin suggested a small fix.
%%
%% Revision 1.1  1999/11/16 20:54:33  ess
%% Another bit of documentation
%%
%% Revision 1.11  1998/10/12 21:09:20  rossini
%% added andy's notes.
%%
%% Revision 1.10  1998/10/12 15:53:25  rossini
%% emacs clarification made (thanks Martin!).
%%
%% Revision 1.9  1998/10/12 15:48:16  rossini
%% Released in semi-final form.
%%
%%

\documentclass{article}

\addtolength{\textheight}{2in}
\addtolength{\textwidth}{1in}
\addtolength{\topmargin}{-1in}
\addtolength{\oddsidemargin}{-1.0in}

\usepackage{palatino}
\usepackage{html}

\title{A Quick Introduction to ESS}
\author{A.J. Rossini}

\begin{document}

\maketitle

This document can be found at
\begin{center}
  \htmladdnormallink
  {http://www.biostat.washington.edu/\~{}rossini/talk/ESS\_intro/}
  {http://www.biostat.washington.edu/\~{}rossini/talk/ESS\_intro/}
\end{center}
The example file for this session is
\htmladdnormallink{rossini.example.R}
{http://www.biostat.washington.edu/\~{}rossini/talk/ESS\_intro/rossini.example.R},
which can be retrieved (from the Biostat machines) by 
\begin{verbatim}
        cp ~rossini/public_html/talk/ESS_intro/rossini.example.R .
\end{verbatim}
to your current working directory.  (note that the final ``.'' is very
important!).

For convenience, the \htmladdnormallink{latex}
{http://www.biostat.washington.edu/\~{}rossini/talk/ESS\_intro/ESS\_intro.tex}
and \htmladdnormallink{postscript}
{http://www.biostat.washington.edu/\~{}rossini/talk/ESS\_intro/ESS\_intro.ps}
versions are also available.

\section{Common Emacs Information}
\label{sec:emacs}

This is not a tutorial for Emacs.  That is a subject for another session.

Basic notation for key sequences:
\begin{itemize}
\item \verb+[tab]+ is the TAB (indent) key.
\item \verb+C-k+ refers to holding down the control (ctrl) key \textbf{WHILE}
  pressing ``k''.
\item \verb+M-k+ refers to pressing the Escape key (ESC),
  \textbf{THEN} pressing ``k''.
\end{itemize}
\textbf{Only run one Emacs session}.  This is a cardinal rule, that
you should try not to violate.  To load in (visit) new files, do:
\begin{itemize}
\item \verb+C-x C-f+    (replaces current file in window with new)
\item \verb+C-x 4 C-f+  (load new file in different window)
\item \verb+C-x 5 C-f+  (load new file in different frame)
\end{itemize}
and to switch to another file, do
\begin{itemize}
\item \verb+C-x b+    (switch to new buffer in window)
\item \verb+C-x 4 b+  (replaces current file in different window)
\item \verb+C-x 5 b+  (replaces current file in different frame)
\end{itemize}

Buffers are the representations of the files you are editing.  You can
treat them as the files themselves.


\subsection{Useful (X)Emacs Commands for UW Biostat}
\label{sec:emacs:uwbiostat}

In the following, \emph{``Emacs''} can be used instead of
\emph{``XEmacs''}.

This section is thanks to \htmladdnormallink{Andy
  Dunning}{mailto:adunning@biostat.washington.edu} and
\htmladdnormallink{Greg Warnes}{mailto:warnes@biostat.washington.edu}.

It's also available as a \htmladdnormallink{crib sheet text document}
{http://www.biostat.washington.edu/\~{}rossini/talk/ESS\_intro/emacs.txt}.

\begin{verbatim}
                        USEFUL XEMACS COMMANDS
                        ======================

STARTING XEMACS  (Currently on GIBSON, GORN, SOL, ATLAS, ABACUS)
---------------
        rsh <machine>           login to machine <machine>

        xemacs <filename>       start xemacs, edit <filename>
        xemacs -f S             start xemacs, run S-plus
        xemacs -nw              start xemacs in _text_ mode (nw="No Window")
                                (useful over telnet session from home)

ANY EMACS BUFFER
----------------

        MOVING AROUND
        -------------
        C-v             Move forward one screenful
        M-v             Move backward one screenful
        C-l             Clear screen and redisplay everything
        M- ->           Meta-<right> - moves forward a word 
        M- <-           Meta-<left> - moves back a word
        M- |^           Meta-<up> - move up a paragraph
        M- V            Meta-<down> - move down a paragraph
        M- <            Meta-<less than> - move to end of file
        
        CUT AND PASTE
        -------------
        C-d             _D_elete
        C-k             _K_ill from the cursor position to end of line
        C-y             Recover/Paste (_Y_ank) killed text (repeat to copy) 
        M-y             recover former killed text (after C-y.  Repeat to go 
                        back through stack).
        C-x u           _U_ndo

        LOADING/SAVING FILES
        --------------------
        C-x C-f         _F_ind a file
        C-x C-s         _S_ave the file

        If you find a second file with C-x C-f, the first file remains
        inside Emacs.  You can switch back to it by finding it again with
        C-x C-b.  This way you can get quite a number of files inside Emacs.

        MANAGING BUFFERS / WINDOWS
        --------------------------
        C-x 0           Move between windows 
        C-x 1           One window (i.e., kill all other windows).

        C-x b           Switch to new _b_uffer
        C-x C-b         List _b_uffers

        SEARCH and REPLACE
        ------------------
        M-x (then) replace-string
                        Replace string
        C-s             _S_earch forward - repeat to move to next occurence
        C-r             Search _r_everse - repeat to move to previous occurence
                        
        MISC
        ----
        C-h or C-h ?    _H_elp
        C-h c (command) _H_elp on this _c_ommand

        C-u 8 (character or command)   
                        Repeat character or command 8 times

        C-g             Stop, undo, unhang.
        C-x C-c         stop editing and exit (_c_lose) Emacs  

        STARTING SPLUS / ESS
        --------------------
        M-x S           Start _S_-plus process buffer
        M-x S-mode      Change mode of current buffer to S-plus code editing

S EXECUTION BUFFER (Usually named "*S*" or similar, mode line says "iESS")
------------------

        C-c C-d         _D_ump S-plus object or function into new editing 
                           buffer.

        C-c C-v xxx     get S-plus help on "xxx"


S CODE EDITING BUFFER (Usually named for the file being edited, mode line 
---------------------           says "ESS[S]")

        C-c C-j         Send line to S
        C-c C-n         Send line to S and move down to _n_ext line
        C-c C-r         Send highlighted _r_egion to S
        C-c C-b         Send whole _b_uffer to S
        C-c C-f         Send _f_unction where cursor is to S

        C-c C-v xxx     get S-plus help on "xxx"
\end{verbatim}

\section{Replacing Command-line Usage}
\label{sec:commandline}

\subsection{Start-up}
\label{sec:commandline:startup}

\begin{enumerate}
\item To run from the command-line in a non-windowing environment:
\begin{verbatim}
  xemacs -f S
\end{verbatim}
\item To run from the command-line in a windowing environment:
\begin{verbatim}
  xemacs -f S &
\end{verbatim}
\end{enumerate}
(note that depending on the system, you might be using \verb+emacs+,
not \verb+xemacs+).

\textbf{Optional: } The first time that one runs this, you should
construct the object list.  This is done by:
\begin{verbatim}
      M-x ess-create-object-name-db
\end{verbatim}
or
\begin{verbatim}
      M-x ess-create-obj[tab]
\end{verbatim}
where \verb+[tab]+ is the TAB key.

One can replace \verb+S+ with \verb+R+ or \verb+XLS+, to run a
different version.  The object database feature currently only works
with Splus and R.

\subsection{Replacing Command-line Usage}
\label{sec:commandline:usage}

To enter commands, you generally need to be at a command prompt (i.e.
``\verb+> +'').  But there are some nice exceptions.

The follow applies primarily to \verb+Splus+ and \verb+R+.

\begin{enumerate}
\item To get help on a function (help(``lm'')) without spoiling your
  input line: \verb+C-c C-v+
\item Completion of objects (functions and data): 
  \begin{enumerate}
  \item \verb+C-c [tab]+ 
  \item \verb+[tab]+ (sometimes).
\end{enumerate}
\item Search command-line history ``manually'', matching on current input
  \begin{enumerate}
  \item backwards: \verb+M-p+
  \item forwards:  \verb+M-n+
  \end{enumerate}
\item Complete current line based on command-line history:
  \begin{enumerate}
  \item backwards: \verb+\C-[uparrow]-p+
  \item forwards:  \verb+M-n+
  \end{enumerate}
\item If you are reviewing old commands, to re-enter it one (with the
  cursor on the line): \verb+[return]+.  
\end{enumerate}

Many other commands, as well...

\section{Replacing Cut-and-Paste}
\label{sec:cutpaste}

The next stage of statistics package usage is usually to cut-and-paste
from an editor.  Since we are within an editor, this is moot.

\textbf{Use the following suffices for your files:}
\begin{itemize}
\item \verb+.S+, such as \verb+critical_simulation.S+
\item \verb+.R+, such as \verb+speedy_simulation.R+
\end{itemize}

\subsection{Cut and Paste}
\label{sec:cutpaste:usual}

You \textbf{can} cut and paste.  It's pretty identical, and a bit ugly.

\subsection{Efficient Methods 1}
\label{sec:cutpaste:eff1}

\textbf{This works from the process (inferior ESS, or iESS) buffer}

One improvement is to use a \verb+source()+-like facility.

\begin{enumerate}
\item To source a file into Splus (within ESS): \verb+C-c C-l+  (load file)
\item To find what the errors are (if any): \verb+C-c `+ (backquote).
\end{enumerate}

The latter will tell you what the error is.  You'll have to go back to
the file and edit it.

\subsection{Efficient Methods 2}
\label{sec:cutpaste:eff2}

\textbf{This works from the editing (ESS) buffer}

Better yet, use a file, and send material from the file straight to
the process.  This works if the file ends in the proper suffix (and
hence, the mode at the bottom should say ``ESS'').

The following is possible:
\begin{itemize}
\item Send current line to S: \verb+C-c C-j+
\item Send current function to S (assumes the cursor is in the
  function body): \verb+C-c C-f+.
\item Send current region (highlighted) to S  \verb+C-c C-r+
\item Send whole buffer/file to S  \verb+C-c C-b+
\end{itemize}


\section{Editing}
\label{sec:edit}

\textbf{This works from the editing (ESS) buffer}

See Section~\ref{sec:cutpaste:eff2} for communication between the code
buffer and the process buffer.

The help commands and object completion commands (only \verb+C-c [TAB]+
version) work.

Syntax-highlighting and formatting are present.  For comment indentation:
\begin{enumerate}
\item \verb+#+ gets moved to the right-side of the line
\item \verb+##+ is placed at the current indentation level
\item \verb+###+ is placed flush-left.
\end{enumerate}

To dump an object into a buffer (for editing, saving, possible reloading):
\begin{enumerate}
\item \verb+C-c C-d+ dumps the named object into an editing buffer (in
  ESS mode).
\end{enumerate}


\section{Advanced Usage}
\label{sec:advanced}

\begin{itemize}
\item preliminary integration with noweb, for literate programming and
  data analysis (another talk)
\item Has a transcript mode for recreating work and providing
  demonstrations.
\item Except for object-completion, everything mentioned here works
  \textbf{identically} for Stata, XLispStat, and SAS.
\item Makes versioning (version control, document revision history)
  simple.
\end{itemize}
\end{document}