Initial Commit
[packages] / xemacs-packages / ess / texi / ess.texi
1 \input texinfo   @c -*-texinfo-*-
2 @comment %**start of header
3 @setfilename ess.info
4 @settitle ESS --- Emacs Speaks Statistics
5 @comment %**end of header
6
7 @synindex pg vr
8
9 @include ess-defs.texi
10 @titlepage
11 @title ESS --- Emacs Speaks Statistics
12 ESS version
13 @include ../VERSION
14
15 @author The ESS Developers (A.J. Rossini, R.M. Heiberger, K. Hornik,
16 @author M. Maechler, R.A. Sparapani  and S.J. Eglen)
17 @c @author (Formerly by: Doug Bates, Ed Kademan, Frank Ritter
18 @c @author                and David Smith)
19 @c @ifhtml
20 @c <P><HR></P>
21 @c @end ifhtml
22 @c
23 @author Current Documentation by The ESS Developers
24 @author Copyright @copyright{} 2002--2005 The ESS Developers
25 @author Copyright @copyright{} 1996--2001 A.J. Rossini
26 @c (@email{rossini@@biostat.washington.edu})
27 @c @author Department of Biostatistics
28 @c @author University of Washington, USA.
29 @author Original Documentation by David M. Smith
30 @author Copyright @copyright{} 1992--1995 David M. Smith
31 @c (@email{D.M.Smith@@lancaster.ac.uk})
32 @c @author Department of Mathematics and Statistics
33 @c @author Lancaster University, UK
34 @c @page
35 @c @vskip 0pt plus 1filll
36 @c @sp 2
37 @author Permission is granted to make and distribute verbatim copies of this
38 @author manual provided the copyright notice and this permission notice are
39 @author preserved on all copies.
40 @author Permission is granted to copy and distribute modified versions of this
41 @author manual under the conditions for verbatim copying, provided that the
42 @author entire resulting derived work is distributed under the terms of a
43 @author permission notice identical to this one.
44
45 @end titlepage
46
47 @ifnottex
48 @majorheading ESS --- Emacs Speaks Statistics
49
50 @dircategory Emacs
51 @direntry
52 * ESS: (ess). Emacs Speaks Statistics (S/S+/R, SAS, BUGS, Stata, XLisp-Stat).
53 @end direntry
54 @c node-name,  next,  previous,  up
55 @node Top, Introduction, (dir), (dir)
56 @top ESS: Emacs Speaks Statistics
57
58 ESS version
59 @include ../VERSION
60
61 @display
62 by  A.J. Rossini,
63     R.M. Heiberger,
64     K. Hornik,
65     M. Maechler,
66     R.A. Sparapani
67 and S.J. Eglen.
68 @end display
69
70 @c (Formerly: Doug
71 @c Bates, Ed Kademan, Frank Ritter and David Smith).
72 @quotation
73 Emacs Speaks Statistics (ESS) provides an intelligent, consistent
74 interface between the user and the software.  ESS interfaces with
75 SAS, S-PLUS, R, BUGS and other statistical analysis packages under
76 the Unix, Microsoft Windows, and Apple Mac operating systems.  ESS
77 is itself a package within the emacs text editor and uses emacs
78 features to streamline the creation and use of statistical software.
79 ESS knows the syntax and grammar of statistical analysis packages
80 and provides consistent display and editing features based on that
81 knowledge.  ESS assists in interactive and batch execution of
82 statements written in these statistical analysis languages.
83 @end quotation
84
85 @end ifnottex
86
87 @menu
88 * Introduction::                Overview of features provided by this package
89 * Installation::                Installing ESS on your system
90
91 * Interactive ESS::             Interacting with statistical programs
92 * Entering commands::           Interacting with the ESS process
93 * Transcript Mode::             Manipulating saved transcript files
94
95 * ESS for the S family::
96 * Editing::                     How to create/edit objects and functions
97 * Editing R documentation files::
98 * Help::                        Reading help files
99
100 * ESS for SAS::
101 * ESS for BUGS::
102
103 * Miscellaneous::               Other features of ESS
104 * Mailing lists/bug reports::   How to get assistance with ESS
105 * Customization::               Customizing ESS
106
107 * Key Index::
108 * Concept Index::
109 * Variable and command index::
110 @c
111 @c @detailmenu
112 @c  --- The Detailed Node Listing ---
113 @c
114 @c Introduction to ESS
115 @c
116 @c * Features::                    Why should I use ESS?
117 @c * New features::
118 @c * Credits::                     Authors of and contributors to ESS
119 @c * Latest version::              Getting the latest version of ESS
120 @c * Manual::                      How to read this manual
121 @c
122 @c Installing ESS on your system
123 @c * Unix installation::              Installing ESS on your Unix system
124 @c * Microsoft Windows installation:: Installing ESS on your MS Windows system
125 @c * Requirements::         emacs, Operating Systems and Statistical Packages
126 @c * System dependent::               Other variables you may need to change
127 @c
128 @c Starting the ESS process
129 @c
130 @c * Multiple ESS processes::
131 @c * ESS processes on Remote Computers::
132 @c * Customizing startup::         Changing the startup actions
133 @c
134 @c Help for the S family
135 @c
136 @c * ESS(S)--Editing files::
137 @c * iESS(S)--Inferior ESS processes::
138 @c * Handling and Reusing Transcripts::
139 @c * ESS-help--assistance with viewing help::
140 @c * Philosophies for using ESS(S)::
141 @c * Scenarios for use (possibilities--based on actual usage)::
142 @c * Customization Examples and Solutions to Problems::
143 @c
144 @c Help for SAS
145 @c
146 @c * ESS(SAS)--Design philosophy::
147 @c * ESS(SAS)--Editing files::
148 @c * iESS(SAS)--Interactive SAS processes::
149 @c * ESS(SAS)--Batch SAS processes::
150 @c * ESS(SAS)--Function keys for batch processing::
151 @c * ESS(SAS)--TAB key::
152 @c * ESS(SAS)--Usage scenarios::
153 @c * iESS(SAS)--Common problems::
154 @c * ESS(SAS)--MS Windows::
155 @c
156 @c Interacting with the ESS process
157 @c
158 @c * Command-line editing::        Entering commands and fixing mistakes
159 @c * Completion::                  Completion of object names
160 @c * Completion details::          Advanced completion concepts
161 @c * Transcript::                  Manipulating the transcript
162 @c * Command History::             Command History
163 @c * History expansion::           References to historical commands
164 @c * Hot keys::                    Hot keys for common commands
165 @c * Statistical Process running in ESS?::
166 @c * Other::                       Other commands provided by inferior-ESS
167 @c
168 @c Manipulating the transcript
169 @c
170 @c * Last command::                Manipulating the output from the last command
171 @c * Process buffer motion::       Viewing older commands
172 @c * Transcript resubmit::         Re-submitting commands from the transcript
173 @c * Saving transcripts::          Keeping a record of your S session
174 @c
175 @c Editing S functions
176 @c
177 @c * Edit buffer::                 Edit objects in a specialized buffer
178 @c * Loading::                     Loading source files into the ESS process
179 @c * Error Checking::              Detecting errors in source files
180 @c * Evaluating code::             Sending code to the ESS process
181 @c * Indenting::                   Indenting and formatting @Sl{} code
182 @c * Other edit buffer commands::  Commands for motion, completion and more
183 @c * Source Files::                Maintaining @Sl{} source files
184 @c * Source Directories::          Names and locations of dump files
185 @c
186 @c Manipulating saved transcript files
187 @c
188 @c * Resubmit::                    Resubmitting commands from the transcript file
189 @c * Clean::                       Cleaning transcript files
190 @c
191 @c Other features of ESS
192 @c
193 @c * Highlighting::                Syntactic highlighting of buffers
194 @c * Graphics::                    Using graphics with ESS
195 @c * Object Completion::
196 @c
197 @c Using graphics with ESS
198 @c
199 @c * printer::                     The printer() graphics driver
200 @c * X11::                         The X11() (and other X-windows based) driver
201 @c
202 @c Bugs and Bug Reporting, Mailing Lists
203 @c
204 @c * Bugs::
205 @c * Reporting Bugs::
206 @c * Mailing Lists::
207 @c
208 @c Customizing ESS
209 @c
210 @c * Variables::                   Variables for customization
211 @c * Hooks::                       Customizing ESS with hooks
212 @c * Keybindings::                 Changing the default ESS keybindings
213 @c
214 @c Variables for customization
215 @c
216 @c * Variables for starting ESS::  Variables for starting ESS
217 @c * Dump file variables::         Variables for dump files
218 @c * Indentation variables::       Variables controlling indentation
219 @c * Variables controlling interaction::  Variables controlling interaction
220 @c                                      with the ESS process
221 @c @end detailmenu
222 @end menu
223
224 @comment  node-name,  next,  previous,  up
225 @node Introduction, Installation, Top, Top
226 @chapter Introduction to ESS
227 @cindex introduction
228
229 The S family (@Sl{}, Splus and R) and SAS statistical analysis packages
230 provide sophisticated statistical and graphical routines for manipulating
231 data.   @b{E}macs @b{S}peaks @b{S}tatistics (ESS) is based on the merger
232 of two pre-cursors, S-mode and SAS-mode, which provided support for the
233 S family and SAS respectively.  Later on, Stata-mode was also incorporated.
234
235 ESS provides a common, generic, and useful interface, through emacs, to
236 many statistical packages.  It currently supports the S family, SAS, BUGS,
237 Stata and XLisp-Stat with the level of support roughly in that order.
238
239 A bit of notation before we begin.  @emph{emacs} refers to both
240 @emph{GNU Emacs} by the Free Software Foundation, as well as
241 @emph{XEmacs} by the XEmacs Project.  The emacs major
242 mode @code{ESS[language]}, where @code{language} can take values such as
243 @code{S}, @code{SAS}, or @code{XLS}.  The inferior process interface
244 (the connection between emacs and the running process) referred to as inferior ESS
245 (@code{iESS}), is denoted in the modeline by @code{ESS[dialect]}, where
246 @code{dialect} can take values such as @code{S3}, @code{S4}, @code{S+3},
247 @code{S+4}, @code{S+5}, @code{S+6}, @code{S+7}, @code{R}, @code{XLS}, @code{VST}, @code{SAS}.
248
249 Currently, the documentation contains many references to @cite{`S'}
250 where actually any supported (statistics) language is meant, i.e., `S'
251 could also mean `XLisp-Stat' or `SAS'.
252
253 @cindex interactive use of S
254
255 @cindex using S interactively
256 For exclusively interactive users of S, ESS provides a number of
257 features to make life easier.  There is an easy to use command history
258 mechanism, including a quick prefix-search history.  To reduce typing,
259 command-line completion is provided for all @Sl{} objects and ``hot
260 keys'' are provided for common @Sl{} function calls.  Help files are
261 easily accessible, and a paging mechanism is provided to view them.
262 Finally, an incidental (but very useful) side-effect of ESS is that a
263 transcript of your session is kept for later saving or editing.
264
265 @cindex transcripts of S sessions
266 No special knowledge of Emacs is necessary when using @Sl{}
267 interactively under ESS.
268
269 @cindex programming in S
270 For those that use @Sl{} in the typical edit--test--revise cycle when
271 programming @Sl{} functions, ESS provides for editing of @Sl{} functions
272 in Emacs edit buffers.  Unlike the typical use of @Sl{} where the editor
273 is restarted every time an object is edited, ESS uses the current Emacs
274 session for editing.  In practical terms, this means that you can edit
275 more than one function at once, and that the ESS process is still
276 available for use while editing.  Error checking is performed on
277 functions loaded back into S, and a mechanism to jump directly to the
278 error is provided.  ESS also provides for maintaining text versions of
279 your @Sl{} functions in specified source directories.
280
281 @menu
282 * Features::                    Why should I use ESS?
283 * New features::
284 * Credits::                     Authors of and contributors to ESS
285 * Latest version::              Getting the latest version of ESS
286 * Manual::                      How to read this manual
287 @end menu
288
289 @comment  node-name,  next,  previous,  up
290 @node Features, New features, Introduction, Introduction
291 @section Why should I use ESS?
292
293 Statistical packages are powerful software systems for manipulating and
294 analyzing data, but their user interfaces often leave something something
295 to be desired:  they offer weak editor functionality and they differ
296 among themselves so markedly that you have to re-learn how to do those
297 things for each package.  ESS is a package which is designed to make
298 editing and interacting with statistical packages more uniform,
299 user-friendly and give you the power of emacs as well.
300
301 ESS provides several features which make it easier to interact with the
302 ESS process (a connection between your buffer and the statistical
303 package which is waiting for you to input commands).  These include:
304
305 @itemize @bullet
306 @item
307 @b{Command-line editing} for fixing mistakes in commands before they are
308 entered.  The @samp{-e} flag for S-plus provides something similar to
309 this, but here you have the full range of Emacs commands rather than a
310 limited subset.  However, other packages such as XLisp-Stat and S3 do not
311 necessarily have features like this built-in.
312 @xref{Command-line editing}.
313
314 @item
315 @b{Searchable command history} for recalling previously-submitted
316 commands.  This provides all the features of the @samp{Splus -e} history
317 mechanism, plus added features such as history searching.
318 @xref{Command History}.
319
320 @item
321 @b{Command-line completion} of both object and file names for quick
322 entry.  This is similar to @code{tcsh}'s facility for filenames; here it
323 also applies to object names and list components.
324 @xref{Completion}.
325
326 @item
327 @b{Hot-keys} for quick entry of commonly-used commands in `S' such as
328 @code{objects()} and @code{search()}.
329 @xref{Hot keys}.
330
331 @item
332 @b{Transcript recording} for a complete record of all the actions in an
333 S session.
334 @xref{Transcript}.
335
336 @item
337 @b{Interface to the help system}, with a specialized mode for viewing S
338 help files.
339 @xref{Help}.
340
341 @end itemize
342
343 If you commonly create or modify @Sl{} functions, you will have found
344 the standard facilities for this (the @samp{fix()} function, for
345 example) severely limiting.  Using S's standard features, one can only
346 edit one function at a time, and you can't continue to use @Sl{} while
347 editing.  ESS corrects these problems by introducing the following
348 features:
349
350 @itemize @bullet
351 @item
352 @b{Object editing}.  ESS allows you to edit more than one function
353 simultaneously in dedicated Emacs buffers.  The ESS process may
354 continue to be used while functions are being edited.
355 @xref{Edit buffer}.
356
357 @item
358 @b{A specialized editing mode} for @Sl{} code, which provides syntactic
359 indentation and highlighting.
360 @xref{Indenting}.
361
362 @item
363 @b{Facilities for loading and error-checking source files}, including a
364 keystroke to jump straight to the position of an error in a source file.
365 @xref{Error Checking}.
366
367 @item
368 @b{Source code revision maintenance}, which allows you to keep historic
369 versions of @Sl{} source files.
370 @xref{Source Files}.
371
372 @item
373 @b{Facilities for evaluating @Sl{} code} such as portions of source
374 files, or line-by-line evaluation of files (useful for debugging).
375 @xref{Evaluating code}.
376 @end itemize
377
378 Finally, ESS provides features for re-submitting commands from saved
379 transcript files, including:
380
381 @itemize @bullet
382
383 @item
384 @b{Evaluation of previously entered commands}, stripping away
385 unnecessary prompts.
386 @xref{Transcript resubmit}.
387
388 @end itemize
389
390 @comment  node-name,  next,  previous,  up
391 @node New features, Credits, Features, Introduction
392 @section New features in ESS
393
394 @include newfeat.texi
395
396 @comment  node-name,  next,  previous,  up
397 @node Credits, Latest version, New features, Introduction
398 @section Authors of and contributors to ESS
399
400 @include credits.texi
401
402 @comment  node-name,  next,  previous,  up
403 @node Latest version, Manual, Credits, Introduction
404 @section Getting the latest version of ESS
405
406 @include getting.texi
407
408 @comment  node-name,  next,  previous,  up
409 @node Manual,  , Latest version, Introduction
410 @section How to read this manual
411
412 If you need to install ESS, read @ref{Installation} for details on what
413 needs to be done before proceeding to the next chapter.
414
415 In this manual we use the standard notation for describing the
416 keystrokes used to invoke certain commands.  @kbd{C-<chr>} means hold
417 the CONTROL key while typing the character <chr>. @kbd{M-<chr>} means
418 hold the META or EDIT or ALT key down while typing <chr>. If there is no
419 META, EDIT or ALT key, instead press and release the ESC key and then
420 type <chr>.
421
422 All ESS commands can be invoked by typing @kbd{M-x command}.  Most of
423 the useful commands are bound to keystrokes for ease of use.  Also, the
424 most popular commands are also available through the emacs menubar, and
425 finally, if available, a small subset are provided on the toolbar.
426 Where possible, keybindings are similar to other modes in emacs to
427 strive for a consistent user interface within emacs, regardless of the
428 details of which programming language is being edited, or process being
429 run.
430
431 Some commands, such as @kbd{M-x R} can accept an optional `prefix'
432 argument.  To specify the prefix argument, you would type @kbd{C-u}
433 before giving the command.  e.g. If you type @kbd{C-u M-x R}, you will
434 be asked for command line options that you wish to invoke the R process
435 with.
436
437 Emacs is often referred to as a `self-documenting' text editor.  This
438 applies to ESS in two ways.  First, limited documentation about each ESS
439 command can be obtained by typing @kbd{C-h f}.  For example, if you type
440 @kbd{C-h f ess-eval-region}, documentation for that command will appear
441 in a separate *Help* buffer.  Second, a complete list of keybindings
442 that are available in each ESS mode and brief description of that mode
443 is available by typing @kbd{C-h m} within an ESS buffer.
444
445 Emacs is a versatile editor written in both C and lisp; ESS is written
446 in the Emacs lisp dialect (termed `elisp') and thus benefits from the
447 flexible nature of lisp.  In particular, many aspects of ESS behaviour
448 can be changed by suitable customization of lisp variables.  This manual
449 mentions some of the most frequent variables.  A full list of them
450 however is available by using the Custom facility within emacs.  (Type
451 @kbd{M-x customize-group RET ess RET} to get started.)
452 @ref{Customization} provides details of common user variables you can
453 change to customize ESS to your taste, but it is recommended that you
454 defer this section until you are more familiar with ESS.
455
456 @comment  node-name,  next,  previous,  up
457 @node Installation, Interactive ESS, Introduction, Top
458 @chapter Installing ESS on your system
459 @cindex installation
460
461 The following section details those steps necessary to get ESS running
462 on your system.
463
464 @menu
465 * Unix installation::              Installing ESS on your Unix system
466 * Microsoft Windows installation:: Installing ESS on your MS Windows system
467 * Requirements::         emacs, Operating Systems and Statistical Packages
468 @end menu
469
470 @c FIXME: the following contains @node s  *and* is also included by readme.texi
471 @c -----  which does *not* include 'requires.texi'
472 @c         ==> *must* give node pointer problems!
473 @include inst_tar.texi
474
475 @node Requirements, , Microsoft Windows installation, Installation
476 @comment node-name,  next,  previous,  up
477 @section Requirements
478 @include requires.texi
479
480
481 @comment  node-name,  next,  previous,  up
482 @node Interactive ESS, Entering commands, Installation, Top
483 @chapter Interacting with statistical programs
484
485 As well as using ESS to edit your source files for statistical programs,
486 you can use ESS to run these statistical programs.  In this chapter, we
487 mostly will refer by example to running S from within emacs.  The emacs
488 convention is to name such proceses running under its control as
489 `inferior processes'.  This term can be slightly misleading, in which
490 case these processes can be thought of `interactive processes'.  Either
491 way, we use the term `iESS' to refer to the Emacs mode used to interact
492 with statistical programs.
493
494
495 @comment  node-name,  next,  previous,  up
496 @menu
497 * Starting up::                 
498 * Multiple ESS processes::      
499 * ESS processes on Remote Computers::  
500 * S+elsewhere and ESS-elsewhere::  
501 * Customizing startup::         
502 @end menu
503
504 @node Starting up, Multiple ESS processes, Interactive ESS, Interactive ESS
505 @section Starting an ESS process
506 @cindex starting ESS
507 @cindex running S
508
509 To start an @Sl{} session, simply type @kbd{M-x S RET}.
510 @pindex S
511
512 @cindex ESS process directory
513 @cindex starting directory
514 @cindex working directory
515 @cindex directories
516
517 S will then (by default) ask the question
518 @example
519 S starting data directory?
520 @end example
521 @noindent
522 Enter the name of the directory you wish to start @Sl{} from (that is,
523 the directory you would have @code{cd}'d to before starting @Sl{} from
524 the shell).  This directory should have a @file{.Data} subdirectory.
525
526 You will then be popped into a buffer
527 @cindex ESS process buffer
528 @cindex process buffer
529 with name @samp{*S*} which will be used
530 for interacting with the ESS process, and you can start entering commands.
531
532
533 @comment  node-name,  next,  previous,  up
534 @node Multiple ESS processes,  ESS processes on Remote Computers, Starting up, Interactive ESS
535 @section Running more than one ESS process
536 @cindex Multiple ESS processes
537
538 ESS allows you to run more than one ESS process simultaneously in the
539 same session.  Each process has a name and a number; the initial process
540 @cindex process names
541 (process 1) is simply named (using S-PLUS as an example) @samp{S+3:1}.
542 @comment You may start a new process by passing a numeric argument to
543 @comment @kbd{M-x S}.  For example, typing @kbd{ESC 2 M-x S} starts up
544 @comment an ESS process with name @samp{S2}, in a buffer whose name
545 @comment is initially @samp{*S2*}.
546 The name of the process is shown in the mode line in square brackets
547 (for example, @samp{[S+3:2]}); this is useful if the process buffer is
548 renamed.  Without a prefix argument, @kbd{M-x S} starts a new ESS
549 process, using the first available process number.  With a prefix
550 argument (for R), @kbd{C-u M-x R} allows for the specification of
551 command line options.
552
553 @pindex ess-request-a-process
554 You can switch to any active ESS process with the command
555 @samp{M-x ess-request-a-process}.  Just enter the name of the process
556 you require; completion is provided over the names of all running S
557 processes.  This is a good command to consider binding to a global key.
558
559 @c SJE - commented outl the default behaviour now is to label *S* rather
560 @c than *S:1*.
561 @c @vindex ess-plain-first-buffername
562 @c For the predecessor to ESS (S-mode 4.8), the initial process was not
563 @c visibly numbered, i.e. S instead of S1 was used in the mode-line.  To
564 @c obtain this behavior, set the variable @code{ess-plain-first-buffername}
565 @c to @code{t}.  See @file{ess-site} for how to set this for all users.
566
567
568 @comment  node-name,  next,  previous,  up
569 @node ESS processes on Remote Computers, S+elsewhere and ESS-elsewhere, Multiple ESS processes, Interactive ESS
570 @section ESS processes on Remote Computers
571 @cindex Remote Computers
572 @pindex ess-remote
573 @pindex ESS-elsewhere
574 @pindex S+elsewhere
575
576 ESS works with processes on remote computers as easily as with
577 processes on the local machine.  The recommended way to access a
578 statistical program on remote computer is to start it from a telnet or
579 ssh buffer and then connect ESS to that buffer.
580
581 @enumerate
582 @item Start a new telnet or ssh buffer and connect to the remote computer
583 (e.g. use @samp{M-x telnet} or @samp{M-x ssh}; ssh.el is available at
584 @uref{ftp://ftp.splode.com/pub/users/friedman/emacs-lisp/ssh.el}).
585
586 @item Start the ESS process on the remote machine, for example with one of
587 the commands @samp{Splus}, or @samp{R}, or @samp{sas -stdio}.
588
589 @item Enter the ESS command @samp{M-x ess-remote}.  You will be prompted for
590 a program name.  Enter @samp{sp6} or @samp{r} or @samp{sas} or another
591 valid name.  Your telnet process is now known to ESS.  All the usual
592 ESS commands (@samp{C-c C-n} and its relatives) now work with the S
593 language processes.  For SAS you need to use a different command
594 @samp{C-c i} (that is a regular @samp{i}, not a @samp{C-i}) to send
595 lines from your @file{myfile.sas} to the remote SAS process.
596 @samp{C-c i} sends lines over invisibly.
597 @c and lets SAS display them formatted correctly as in a SAS log file.
598 With ess-remote you get teletype behavior---the data input, the
599 log, and the listing all appear in the same buffer.  To make this work,
600 you need to end every PROC and DATA step with a "RUN;" statement.  The
601 "RUN;" statement is what tells SAS that it should process the preceding
602 input statements.
603
604 @item Graphics (interactive) on the remote machine.  If you run X11
605 (@xref{X11}, X-windows)
606 on both the local and remote machines then you should be able to
607 display the graphs locally by setting the @samp{DISPLAY} environment
608 variable appropriately.  Windows users can download @samp{xfree86}
609 from cygwin.
610
611 @item Graphics (static) on the remote machine.
612 If you don't run the X window system on the local machine, then you can write
613 graphics to a file on the remote machine, and display the file in
614 a graphics viewer on the local machine.  Most statistical software can
615 write one or more of postscript, GIF, or JPEG files.
616 Depending on the versions of emacs and the operating system that you
617 are running, emacs itself may display @samp{.gif} and @samp{.jpg}
618 files.  Otherwise, a graphics file viewer will be needed.
619 Ghostscript/ghostview may be downloaded to display @samp{.ps} and
620 @samp{.eps} files.  Viewers for GIF and JPEG are usually included with
621 operating systems.  @xref{ESS(SAS)--Function keys for batch processing},
622 for more information on using the F12 key for displaying graphics files
623 with SAS.
624 @end enumerate
625
626 Should you or a colleague inadvertently start a statistical process in
627 an ordinary @samp{*shell*} buffer, the @samp{ess-remote} command can
628 be used to convert it to an ESS buffer and allow you to use the ESS
629 commands with it.
630
631 We have two older commands, now deprecated, for accessing ESS processes
632 on remote computers.
633 @xref{S+elsewhere and ESS-elsewhere}.
634
635
636 @comment  node-name,  next,  previous,  up
637 @node S+elsewhere and ESS-elsewhere, Customizing startup, ESS processes on Remote Computers, Interactive ESS
638 @section S+elsewhere and ESS-elsewhere
639
640 These commands are now deprecated.  We recommend @samp{ess-remote}.  We
641 have two versions of the elsewhere function.  @samp{S+elsewhere} is
642 specific for the S-Plus program.  The more general function
643 @samp{ESS-elsewhere} is not as stable.
644
645 @enumerate
646 @item Enter @samp{M-x S+elsewhere}.
647 You will be prompted for a starting directory.  I usually give it my
648 project directory on the local machine, say  @samp{~myname/myproject/}
649
650 Or enter @samp{M-x ESS-elsewhere}.  You will be prompted for an ESS
651 program and for a starting directory.  I usually give it my project
652 directory on the local machine, say @samp{~myname/myproject/}
653
654 @item The @samp{*S+3*} buffer will appear with a prompt from the
655 local operating system (the unix prompt on a unix workstation or with
656 cygwin bash on a PC, or the msdos prompt on a PC without bash).  emacs
657 may freeze because the cursor is at the wrong place.  Unfreeze it with
658 @samp{C-g} then move the cursor to the end with @samp{M->}.
659 With @samp{S+elsewhere} the buffer name is based on the name of the ESS program.
660 @item Enter
661 @samp{telnet myname@@other.machine} (or @samp{ssh myname@@other.machine}).
662 You will be prompted for your password on the remote machine.
663 Use
664 @samp{M-x send-invisible}
665 before typing the password itself.
666
667 @item Before starting the ESS process, type @samp{stty -echo nl}
668 at the unix prompt.  The @samp{-echo} turns off the echo, the
669 @samp{nl} turns off the newline that you see as @samp{^M}.
670
671 @item You are now talking to the unix prompt on the other machine in the
672 @samp{*S+3*} buffer.  cd into the directory for the current project and start
673 the ESS process by entering
674 @samp{Splus} or @samp{R} or @samp{sas -stdio}
675 as appropriate.  If you can login remotely to your Windows 2000, then
676 you should be able to run @samp{Sqpe} on the Windows machine.  I haven't
677 tested this and noone has reported their tests to me.  You will not be
678 able to run the GUI through this text-only connection.
679
680 @item Once you get the S or R or SAS prompt, then you are completely connected.
681 All the @samp{C-c C-n} and related commands work correctly in sending
682 commands from @samp{myfile.s} or @samp{myfile.r} on the PC to the
683 @samp{*S+3*} buffer running the S or R or SAS program on the remote machine.
684
685 @item Graphics on the remote machine works fine.  If you run the X window
686 sysyem on the remote unix machine you should be able to display them in
687 @samp{xfree86} on your PC.  If you don't run X11, then you can write
688 graphics to the postscript device and copy it to your PC with dired and
689 display it with ghostscript.
690 @end enumerate
691
692
693 @comment  node-name,  next,  previous,  up
694 @node Customizing startup,  , S+elsewhere and ESS-elsewhere, Interactive ESS
695 @section Changing the startup actions
696
697 If you do not wish ESS to prompt for a starting directory when starting
698 a new process, set the variable @code{ess-ask-for-ess-directory} to
699 @vindex ess-ask-for-ess-directory
700 @code{nil}.  In this case, the value of the variable @code{ess-directory}
701 @vindex ess-directory
702 is used as the starting directory.  The default value for this variable
703 is your home directory.  If @code{ess-ask-for-ess-directory} has a
704 non-@code{nil} value (as it does by default) then the value of
705 @code{ess-directory} provides the default when prompting for the
706 starting directory.  Incidentally, @code{ess-directory} is an ideal
707 variable to set in @code{ess-pre-run-hook}.
708
709 If you like to keep a record of your @Sl{} sessions, set the variable
710 @code{ess-ask-about-transfile} to @code{t}, and you will be asked for a
711 filename for the transcript before the ESS process starts.
712
713 @defvr {User Option} ess-ask-about-transfile
714 If non-@code{nil}, as for a file name in which to save the session
715 transcript.
716 @end defvr
717
718 @cindex transcript file
719 Enter the name of a file in which to save the transcript at the prompt.
720 If the file doesn't exist it will be created (and you should give it a
721 file name ending in @samp{.St}); if the file already exists the
722 transcript will be appended to the file.  (Note: if you don't set this
723 variable but you still want to save the transcript, you can still do it
724 later --- @pxref{Saving transcripts}.)
725
726 Once these questions are answered (if they are asked at all) the S
727 process itself is started by calling the program name specified in the
728 variable @code{inferior-ess-program}.
729 @vindex inferior-ess-program
730 If you need to pass any arguments to this program, they may be specified
731 in the variable @code{inferior-@var{S_program_name}-args} (e.g. if
732 @code{inferior-ess-program} is @code{"S+"} then the variable to set is
733 @code{inferior-S+-args}.
734 @cindex arguments to S program
735 It is not normally necessary to pass arguments to the @Sl{} program; in
736 particular do not pass the @samp{-e} option to @code{Splus}, since ESS
737 provides its own command history mechanism.
738
739 By default, the new process will be displayed in another window in the
740 current frame.  If you wish your S process to appear in a separate
741 variable, customize the variable @code{inferior-ess-own-frame}.
742
743 @comment  node-name,  next,  previous,  up
744 @node Entering commands, Transcript Mode, Interactive ESS, Top
745 @chapter Interacting with the ESS process
746 @cindex entering commands
747 @cindex commands
748 @cindex sending input
749
750 The primary function of the ESS package is to provide an easy-to-use
751 front end to the @Sl{} interpreter.  This is achieved by running the S
752 process from within an Emacs buffer, so that the Emacs editing commands
753 are available to correct mistakes in commands, etc.  The features of
754 Inferior @Sl{} mode are similar to those provided by the standard Emacs
755 shell mode (@pxref{Shell Mode,,, emacs, The Gnu Emacs Reference
756 Manual}).  Command-line completion of @Sl{} objects and a number of `hot
757 keys' for commonly-used @Sl{} commands are also provided for ease of
758 typing.
759
760 @menu
761 * Command-line editing::        Entering commands and fixing mistakes
762 * Completion::                  Completion of object names
763 * Completion details::          Advanced completion concepts
764 * Transcript::                  Manipulating the transcript
765 * Command History::             Command History
766 * History expansion::           References to historical commands
767 * Hot keys::                    Hot keys for common commands
768 * Statistical Process running in ESS?::
769 * Emacsclient::                 Using emacsclient
770 * Other::                       Other commands provided by inferior-ESS
771 @end menu
772
773 @comment  node-name,  next,  previous,  up
774 @node Command-line editing, Completion, Entering commands, Entering commands
775 @section Entering commands and fixing mistakes
776 @cindex command-line editing
777
778 Sending a command to the ESS process is as simple as typing it in
779 and pressing the @key{RETURN} key:
780
781 @itemize @bullet
782 @item
783 @kbd{RET} (@code{inferior-ess-send-input}) @*
784 @pindex inferior-ess-send-input
785 Send the command on the current line to the ESS process.
786 @end itemize
787
788 If you make a typing error before pressing @kbd{RET} all the usual Emacs
789 editing commands are available to correct it (@pxref{Basic, Basic, Basic
790 editing commands, emacs, The GNU Emacs Reference Manual}).  Once the
791 command has been corrected you can press @key{RETURN} (even if the
792 cursor is not at the end of the line) to send the corrected command to
793 the ESS process.
794
795 ESS provides some other commands which are useful for fixing mistakes:
796
797 @itemize @bullet
798 @item
799 @kbd{C-c C-w} (@code{backward-kill-word}) @*
800 @pindex backward-kill-word
801 Deletes the previous word (such as an object name) on the command line.
802
803 @item
804 @kbd{C-c C-u} (@code{comint-kill-input}) @*
805 @pindex comint-kill-input
806 Deletes everything from the prompt to point.  Use this to abandon a
807 command you have not yet sent to the ESS process.
808
809 @item
810 @kbd{C-c C-a} (@code{comint-bol}) @*
811 @pindex comint-bol
812 Move to the beginning of the line, and then skip forwards past the
813 prompt, if any.
814 @end itemize
815
816 @xref{Shell Mode,,, emacs, The Gnu Emacs Reference Manual}, for other
817 commands relevant to entering input.
818
819 @comment  node-name,  next,  previous,  up
820 @node  Completion, Completion details, Command-line editing, Entering commands
821 @section Completion of object names
822 @cindex completion of object names
823 @cindex command-line completion
824
825 In the process buffer, the @key{TAB} key is for completion, similar to
826 that provided by Shell Mode for filenames.  In Inferior @Sl{} mode,
827 pressing the @key{TAB} key when the cursor is following the first few
828 characters of an object name @emph{completes} the object name; if the
829 cursor is following a file name @kbd{TAB} completes the file name.
830
831 @itemize @bullet
832 @item
833 @kbd{TAB} (@code{comint-dynamic-complete}) @*
834 @pindex comint-dynamic-complete
835 Complete the @Sl{} object name or filename before point.
836 @end itemize
837
838 When the cursor is just after a partially-completed object name,
839 pressing @key{TAB} provides completion in a similar fashion to
840 @code{tcsh}
841 @cindex tcsh
842 except that completion is performed over all known @Sl{} object names
843 instead of file names.  ESS maintains a list of all objects known to S
844 at any given time, which basically consists of all objects (functions
845 and datasets) in every attached directory listed by the @code{search()}
846 command
847 @pindex search()
848 along with the component objects of attached data frames
849 @cindex data frames
850 (if your version of @Sl{} supports them).
851
852 For example, consider the three functions (available in Splus version
853 3.0) called @code{binomplot()}, @code{binom.test()} and
854 @code{binomial()}.  Typing @kbd{bin TAB} after the @Sl{} prompt will
855 insert the characters @samp{om}, completing the longest prefix
856 (@samp{binom}) which distinguishes these three commands.  Pressing
857 @kbd{TAB} once more provides a list of the three commands which have
858 this prefix, allowing you to add more characters (say, @samp{.}) which
859 specify the function you desire.  After entering more characters
860 pressing @kbd{TAB} yet again will complete the object name up to
861 uniqueness, etc.  If you just wish to see what completions exist without
862 adding any extra characters, type @kbd{M-?}.
863
864 @itemize @bullet
865 @item
866 @kbd{M-?} (@code{ess-list-object-completions}) @*
867 @pindex ess-list-object-completions
868 List all possible completions of the object name at point.
869 @end itemize
870
871 ESS also provides completion over the components of named lists accessed
872 using the @samp{$} notation, to any level of nested lists.  This feature
873 is particularly useful for checking what components of a list object
874 exist while partway through entering a command: simply type the object
875 name and @samp{$} and press @kbd{TAB} to see the names of existing list
876 components for that object.
877 @cindex lists, completion on
878 @cindex completion on lists
879
880 @cindex completion on file names
881 Completion is also provided over file names, which is particularly
882 useful when using @Sl{} functions such as @code{get()} or @code{scan()}
883 which require fully expanded file names.  Whenever the cursor is within
884 an @Sl{} string, pressing @kbd{TAB} completes the file name before
885 point, and also expands any @samp{~} or environment variable references.
886
887 If the cursor is not in a string and does not follow a (partial) object
888 name, the @key{TAB} key has a third use: it expands history references.
889 @xref{History expansion}.
890
891 @comment  node-name,  next,  previous,  up
892 @node Completion details, Transcript, Completion, Entering commands
893 @section Completion details
894
895 ESS automatically keeps track of any objects added or deleted to the
896 system (such as new objects created, or directories added to the search
897 list) to make completion as accurate as possible.  Whenever ESS notices
898 that search list has changed
899 @vindex ess-change-sp-regexp
900 @footnote{The variable @code{ess-change-sp-regexp} is a regular
901 expression matching commands which change the search list.  You will
902 need to modify this variable if you have defined custom commands (other
903 than @code{attach}, @code{detach}, @code{collection} or @code{library})
904 which modify the search list.}  when you attach a directory or data
905 frame, the objects associated with it immediately become available for a
906 completion; when it is detached completion is no longer available on
907 those objects.
908
909 To maintain a list of accessible objects for completion, ESS needs to
910 determine which objects are contained in each directory or data frame on
911 the search list.  This is done at the start of each @Sl{} session, by
912 running the @code{objects()} command on every element of the search
913 list.
914
915 @c On some systems, however, this can be rather slow; it's doubly
916 @c frustrating when you consider that most of the directories on the search
917 @c list are the standard @Sl{} libraries, which never change anyway!  When
918 @c ESS was installed, a database of the standard object names should have
919 @c been created which should speed up this process at the start of an S
920 @c session; if it has not been created you will get a warning like
921 @c `S-namedb.el does not exist'.  @xref{Installation}, for information on
922 @c how to create this database.
923
924 Efficiency in completion is gained by maintaining a cache of objects
925 currently known to S; when a new object becomes available or is deleted,
926 only one component of the cache corresponding to the associated
927 directory needs to be refreshed.  If ESS ever becomes confused about
928 what objects are available for completion (such as when if refuses to
929 complete an object you @strong{know} is there), the command @kbd{M-x
930 ess-resynch}
931 @pindex ess-resynch
932 forces the @emph{entire} cache to be refreshed, which should fix the
933 problem.
934
935 @comment  node-name,  next,  previous,  up
936 @node Transcript, Command History, Completion details, Entering commands
937 @section Manipulating the transcript
938
939 Most of the time, the cursor spends most of its time at the bottom of
940 the ESS process buffer, entering commands.  However all the input
941 and output from the current (and previous) ESS sessions is stored in
942 the process buffer (we call this the transcript) and often we want to
943 @cindex transcript
944 move back up through the buffer, to look at the output from previous
945 commands for example.
946
947 Within the process buffer, a paragraph
948 @cindex paragraphs in the process buffer
949 is defined as the prompt, the command after the prompt, and the output
950 from the command.  Thus @kbd{M-@{} and @kbd{M-@}} move you backwards and
951 forwards, respectively, through commands in the transcript.  A
952 particularly useful command is @kbd{M-h} (@code{mark-paragraph}) which
953 will allow you to mark a command and its entire output (for deletion,
954 perhaps).  For more information about paragraph commands,
955 @pxref{Paragraphs, Paragraphs, Paragraphs, emacs, The GNU Emacs
956 Reference Manual}.
957
958 If an ESS process finishes and you restart it in the same process
959 buffer, the output from the new ESS process appears after the output
960 from the first ESS process separated by a form-feed (@samp{^L})
961 character.  Thus pages in the ESS
962 @cindex pages in the process buffer
963 process buffer correspond to ESS sessions.  Thus, for example, you may
964 use @kbd{C-x [} and @kbd{C-x ]} to move backward and forwards through
965 ESS sessions in a single ESS process buffer.  For more information about
966 page commands, @pxref{Pages, Pages, Pages, emacs, The GNU Emacs
967 Reference Manual}.
968
969 @menu
970 * Last command::                Manipulating the output from the last command
971 * Process buffer motion::       Viewing older commands
972 * Transcript resubmit::         Re-submitting commands from the transcript
973 * Saving transcripts::          Keeping a record of your S session
974 @end menu
975
976 @comment  node-name,  next,  previous,  up
977 @node Last command, Process buffer motion, Transcript, Transcript
978 @subsection Manipulating the output from the last command
979
980 Viewing the output of the command you have just entered is a common
981 occurrence and ESS provides a number of facilities for doing this.
982 @c Within the ESS process buffer, the variable @code{scroll-step}
983 @c @vindex scroll-step
984 @c is set to 4 (you can redefine this using @code{inferior-ess-mode-hook}
985 @c @vindex inferior-ess-hook
986 @c if you wish - @pxref{Hooks},) so that the cursor is usually near the
987 @c bottom of the window.
988 Whenever a command produces a longish output, it is possible that the
989 window will scroll, leaving the next prompt near the middle of the
990 window.  The first part of the command output may have scrolled off the
991 top of the window, even though the entire output would fit in the window
992 if the prompt were near the bottom of the window.  If this happens, you
993 can use the command
994
995 @itemize @bullet
996 @item
997 @kbd{C-c C-e} (@code{comint-show-maximum-output}) @*
998 @pindex comint-show-maximum-output
999 Move to the end of the buffer, and place cursor on bottom line of
1000 window.
1001 @end itemize
1002
1003 @noindent
1004 to make more of the last output visible.  (To make this happen
1005 automatically for all inputs, set the variable
1006 @code{comint-scroll-to-bottom-on-input} to @code{t}.)
1007
1008 If the first part of the output is still obscured, use
1009 @cindex reading long command outputs
1010 @itemize @bullet
1011 @item
1012 @kbd{C-c C-r} (@code{comint-show-output}) @*
1013 @pindex comint-show-output
1014 Moves cursor to the previous command line and and places it at the top
1015 of the window.
1016 @end itemize
1017
1018 @noindent
1019 to view it.  Finally, if you want to discard the last command output
1020 altogether, use
1021
1022 @itemize @bullet
1023 @item
1024 @kbd{C-c C-o} (@code{comint-kill-output}) @*
1025 @pindex comint-kill-output
1026 @cindex deleting output
1027 Deletes everything from the last command to the current prompt.
1028 @end itemize
1029
1030 @noindent
1031 to delete it.  Use this command judiciously to keep your transcript to a
1032 more manageable size.
1033
1034 @comment  node-name,  next,  previous,  up
1035 @node Process buffer motion, Transcript resubmit, Last command, Transcript
1036 @subsection Viewing older commands
1037
1038 If you want to view the output from more historic commands than the
1039 previous command, commands are also provided to move backwards and
1040 forwards through previously entered commands in the process buffer:
1041
1042 @itemize @bullet
1043 @item
1044 @kbd{C-c C-p} (@code{comint-previous-input}) @*
1045 @pindex comint-previous-input
1046 Moves point to the preceding command in the process buffer.
1047
1048 @item
1049 @kbd{C-c C-n} (@code{comint-next-input}) @*
1050 @pindex comint-next-input
1051 Moves point to the next command in the process buffer.
1052 @end itemize
1053
1054 @noindent
1055 Note that these two commands are analogous to @kbd{C-p} and @kbd{C-n}
1056 but apply to command lines rather than text lines.  And just like
1057 @kbd{C-p} and @kbd{C-n}, passing a prefix argument to these commands
1058 means to move to the @var{ARG}'th next (or previous) command.  (These
1059 commands are also discussed in @ref{Shell History Copying,,Shell History
1060 Copying,emacs, The GNU Emacs Reference Manual}.)
1061
1062 There are also two similar commands (not bound to any keys by default)
1063 which move to preceding or succeeding commands, but which first prompt
1064 for a regular expression (@pxref{Regexps,,Syntax of Regular
1065 Expression,emacs, The GNU Emacs Reference Manual}), and then moves to
1066 the next (previous) command matching the pattern.
1067
1068 @itemize @bullet
1069 @item
1070 @code{(comint-backward-matching-input regexp arg)} @*
1071 @pindex comint-backward-matching-input
1072 @code{(comint-forward-matching-input regexp arg)} @*
1073 @pindex comint-forward-matching-input
1074 Search backward (forward) through the transcript buffer for the
1075 @var{arg}'th previous (next) command matching @var{regexp}.  @var{arg}
1076 is the prefix argument; @var{regexp} is prompted for in the minibuffer.
1077 @end itemize
1078
1079 @comment  node-name,  next,  previous,  up
1080 @node Transcript resubmit, Saving transcripts, Process buffer motion, Transcript
1081 @subsection Re-submitting commands from the transcript
1082
1083 When moving through the transcript, you may wish to re-execute some of
1084 the commands you find there.  ESS provides three commands to do this;
1085 these commands may be used whenever the cursor is within a command line
1086 in the transcript (if the cursor is within some command @emph{output},
1087 an error is signaled).  Note all three commands involve the @key{RETURN}
1088 key.
1089
1090 @itemize @bullet
1091 @item
1092 @kbd{RET} (@code{inferior-ess-send-input}) @*
1093 @pindex inferior-ess-send-input
1094 Copy the command under the cursor to the current command line, and
1095 execute it.
1096
1097 @item
1098 @kbd{C-c RET} (@code{comint-copy-old-input}) @*
1099 @pindex comint-copy-old-input
1100 Copy the command under the cursor to the current command line, but don't
1101 execute it.  Leaves the cursor on the command line so that the copied
1102 command may be edited.
1103
1104 @item
1105 @kbd{M-RET} (@code{ess-transcript-send-command-and-move}) @*
1106 @pindex ess-transcript-send-command-and-move
1107 Copy the command under the cursor to the current command line, and
1108 execute it.  Moves the cursor to the following command.
1109 @end itemize
1110
1111 When the cursor is not after the current prompt, the @key{RETURN} key
1112 has a slightly different behavior than usual.  Pressing @kbd{RET} on any
1113 line containing a command that you entered (i.e. a line beginning with a
1114 prompt) sends that command to the ESS process once again.  If you
1115 wish to edit the command before executing it, use @kbd{C-c RET} instead;
1116 it copies the command to the current prompt but does not execute it,
1117 allowing you to edit it before submitting it.
1118
1119 These two commands leave the cursor at the new command line, allowing
1120 you to continue with interactive use of S.  If you wish to resubmit a
1121 series of commands from the transcript, consider using @kbd{M-RET}
1122 instead, which leaves the cursor at the command line following the one
1123 you re-submitted.  Thus by using @kbd{M-RET} repeatedly, you can
1124 re-submit a whole series of commands.
1125
1126 These commands work even if if the current line is a continuation line
1127 (i.e. the prompt is @samp{+} instead of @samp{>}) --- in this case all
1128 the lines that form the multi-line command are concatenated together and
1129 the resulting command is sent to the ESS process (currently this is
1130 the only way to resubmit a multi-line command to the ESS process in
1131 one go).  If the current line does
1132 @cindex multi-line commands, resubmitting
1133 not begin with a prompt, an error is signaled.  This feature, coupled
1134 with the command-based motion commands described above, could be used as
1135 a primitive history mechanism.  ESS provides a more sophisticated
1136 mechanism, however, which is described in @ref{Command History}.
1137
1138 @comment  node-name,  next,  previous,  up
1139 @node Saving transcripts,  , Transcript resubmit, Transcript
1140 @subsection Keeping a record of your S session
1141
1142 To keep a record of your @Sl{} session in a disk file, use the Emacs
1143 command @kbd{C-x C-w} (@code{write-file}) to attach a file to the
1144 ESS process buffer.  The name of the process buffer will (probably)
1145 change to the name of the file, but this is not a problem.  You can
1146 still use @Sl{} as usual; just remember to save the file before you quit
1147 Emacs with @kbd{C-x C-s}.  You can make ESS prompt you for a filename in
1148 which to save the transcript every time you start @Sl{} by setting the
1149 variable
1150 @vindex ess-ask-about-transfile
1151 @code{ess-ask-about-transfile} to @code{t}; see @ref{Customizing startup}.
1152 @cindex transcript file names
1153 We recommend you save your transcripts with filenames that end in
1154 @samp{.St}.  There is a special mode (ESS transcript mode ---
1155 @pxref{Transcript Mode}) for editing transcript files which is
1156 automatically selected for files with this suffix.
1157
1158 @cindex editing transcripts
1159 S transcripts can get very large, so some judicious editing is
1160 appropriate if you are saving it in a file.  Use @kbd{C-c C-o} whenever
1161 a command produces excessively long output (printing large arrays, for
1162 example).  Delete erroneous commands (and the resulting error messages
1163 or other output) by moving to the command (or its output) and typing
1164 @kbd{M-h C-w}.  Also, remember that @kbd{C-c C-e} (and other hot keys)
1165 may be used for commands whose output you do not wish to appear in the
1166 transcript.  These suggestions are appropriate even if you are not
1167 saving your transcript to disk, since the larger the transcript, the
1168 more memory your Emacs process will use on the host machine.
1169
1170 Finally, if you intend to produce @Sl{} source code (suitable for using
1171 with @code{source()} or inclusion in an @Sl{} function) from a
1172 transcript, then the command @kbd{M-x ess-transcript-clean-region} may
1173 be of use.
1174 @pindex ess-transcript-clean-region
1175 This command works in any Emacs buffer, and removes all prompts and
1176 command output from an ESS transcript within the current region, leaving
1177 only the commands.  Don't forget to remove any erroneous commands first!
1178
1179 @comment  node-name,  next,  previous,  up
1180 @node Command History, History expansion, Transcript, Entering commands
1181 @section Command History
1182 @cindex command history
1183 @cindex editing commands
1184 @cindex re-executing commands
1185
1186 ESS provides easy-to-use facilities for re-executing or editing previous
1187 commands.  An input history of the last few commands is maintained (by
1188 default the last 50 commands are stored, although this can be changed by
1189 setting the variable @code{comint-input-ring-size} in
1190 @vindex comint-input-ring-size
1191 @code{inferior-ess-mode-hook}.) The simplest history commands simply
1192 select the next and previous commands in the input history:
1193
1194 @itemize @bullet
1195 @item
1196 @kbd{M-p} (@code{comint-previous-input}) @*
1197 @pindex comint-previous-input
1198 Select the previous command in the input history.
1199
1200 @item
1201 @kbd{M-n}  (@code{comint-next-input}) @*
1202 @pindex comint-next-input
1203 Select the next command in the input history.
1204 @end itemize
1205
1206 @noindent
1207 For example, pressing @kbd{M-p} once will re-enter the last command into
1208 the process buffer after the prompt but does not send it to the ESS
1209 process, thus allowing editing or correction of the command before the
1210 ESS process sees it.  Once corrections have been made, press
1211 @kbd{RET} to send the edited command to the ESS process.
1212
1213 If you want to select a particular command from the history by matching
1214 it against a regular expression (@pxref{Regexps,,Syntax of Regular
1215 Expression,emacs, The GNU Emacs Reference Manual}), to search for a
1216 particular variable name for example, these commands are also available:
1217
1218 @itemize @bullet
1219 @item
1220 @kbd{M-r} (@code{comint-previous-matching-input}) @*
1221 @pindex comint-previous-matching-input
1222 Prompt for a regular expression, and search backwards through the input
1223 history for a command matching the expression.
1224
1225 @item
1226 @kbd{M-s} (@code{comint-next-matching-input}) @*
1227 @pindex comint-next-matching-input
1228 Prompt for a regular expression, and search backwards through the input
1229 history for a command matching the expression.
1230 @end itemize
1231
1232 @noindent
1233 A common type of search is to find the last command that began with a
1234 particular sequence of characters; the following two commands provide an
1235 easy way to do this:
1236
1237 @itemize @bullet
1238 @item
1239 @kbd{A-M-r} (@code{comint-previous-matching-input-from-input}) @*
1240 @pindex comint-previous-matching-input-from-input
1241 Select the previous command in the history which matches the string
1242 typed so far.
1243
1244 @item
1245 @kbd{A-M-s} (@code{comint-next-matching-input-from-input}) @*
1246 @pindex comint-next-matching-input-from-input
1247 Select the next command in the history which matches the string typed so
1248 far.
1249 @end itemize
1250
1251 @noindent
1252 Instead of prompting for a regular expression to match against, as they
1253 instead select commands starting with those characters already entered.
1254 For instance, if you wanted to re-execute the last @code{attach()}
1255 command, you may only need to type @kbd{att} and then @kbd{A-M-r} and
1256 @kbd{RET}.  (Note: you may not have an @key{ALT} key on your keyboard,
1257 in which case it may be a good idea to bind these commands to some other
1258 keys.)
1259
1260 @xref{Shell Ring,,Shell History Ring,emacs, The GNU Emacs Reference
1261 Manual}, for a more detailed discussion of the history mechanism.
1262
1263 @comment  node-name,  next,  previous,  up
1264 @node History expansion, Hot keys, Command History, Entering commands
1265 @section References to historical commands
1266
1267 Instead of searching through the command history using the command
1268 described in the previous section, you can alternatively refer to a
1269 historical command directly using a notation very similar to that used
1270 in @code{csh}.  History references are introduced by a @samp{!} or
1271 @samp{^} character and have meanings as follows:
1272
1273 @table @samp
1274 @item !!
1275 The immediately previous command
1276
1277 @item !-@var{N}
1278 The @var{N}th previous command
1279
1280 @item !text
1281 The last command beginning with the string @samp{text}
1282
1283 @item !?text
1284 The last command containing the string @samp{text}
1285 @end table
1286
1287 In addition, you may follow the reference with a @dfn{word designator}
1288 to select particular @dfn{words} of the input.  A word is defined as a
1289 sequence of characters separated by whitespace.  (You can modify this
1290 definition by setting the value of @code{comint-delimiter-argument-list}
1291 to a list of characters that are allowed to separate words and
1292 @vindex comint-delimiter-argument-list
1293 themselves form words.)  Words are numbered beginning with zero.  The
1294 word designator usually begins with a @samp{:} (colon) character;
1295 however it may be omitted if the word reference begins with a @samp{^},
1296 @samp{$}, @samp{*} or @samp{-}.  If the word is to be selected from the
1297 previous command, the second @samp{!}  character can be omitted from the
1298 event specification.  For instance, @samp{!!:1} and @samp{!:1} both
1299 refer to the first word of the previous command, while @samp{!!$} and
1300 @samp{!$} both refer to the last word in the previous command.  The
1301 format of word designators is as follows:
1302
1303 @table @samp
1304 @item 0
1305 The zeroth word (i.e. the first one on the command line)
1306
1307 @item @var{n}
1308 The @var{n}th word, where @var{n} is a number
1309
1310 @item ^
1311 The first word (i.e. the second one on the command line)
1312
1313 @item $
1314 The last word
1315
1316 @item @var{x}-@var{y}
1317 A range of words; @samp{-@var{y}} abbreviates @samp{0-@var{y}}
1318
1319 @item *
1320 All the words except the zeroth word, or nothing if the command had just
1321 one word (the zeroth)
1322
1323 @item @var{x}*
1324 Abbreviates @var{x}-$
1325
1326 @item @var{x}-
1327 Like @samp{@var{x}*}, but omitting the last word
1328 @end table
1329
1330 In addition, you may surround the entire reference except for the first
1331 @samp{!} by braces to allow it to be followed by other (non-whitespace)
1332 characters (which will be appended to the expanded reference).
1333
1334 Finally, ESS also provides quick substitution; a reference like
1335 @samp{^old^new^} means ``the last command, but with the first occurrence
1336 of the string @samp{old} replaced with the string @samp{new}'' (the last
1337 @samp{^} is optional).  Similarly, @samp{^old^} means ``the last
1338 command, with the first occurrence of the string @samp{old} deleted''
1339 (again, the last @samp{^} is optional).
1340
1341 To convert a history reference as described above to an input suitable
1342 for S, you need to @dfn{expand} the history reference, using the
1343 @key{TAB} key.  For this to work, the cursor must be preceded by a space
1344 (otherwise it would try to complete an object name) and not be within a
1345 string (otherwise it would try to complete a filename).  So to expand
1346 the history reference, type @kbd{SPC TAB}.  This will convert the
1347 history reference into an @Sl{} command from the history, which you can
1348 then edit or press @key{RET} to execute.
1349
1350 For example, to execute the last command that referenced the variable
1351 @code{data}, type @kbd{!?data SPC TAB RET}.
1352
1353 @comment  node-name,  next,  previous,  up
1354 @node Hot keys, Statistical Process running in ESS?, History expansion, Entering commands
1355 @section Hot keys for common commands
1356
1357 ESS provides a number of commands for executing the commonly used
1358 functions.  These commands below are basically information-gaining
1359 commands (such as @code{objects()} or @code{search()}) which tend to
1360 clutter up your transcript and for this reason some of the hot keys
1361 display their output in a temporary buffer instead of the process buffer
1362 by default.  This behavior is controlled by the variable
1363 @code{ess-execute-in-process-buffer} which, if
1364 @vindex ess-execute-in-process-buffer
1365 non-@code{nil}, means that these commands will produce their output in
1366 the process buffer instead.  In any case, passing a prefix argument to
1367 the commands (with @kbd{C-u}) will reverse the meaning of
1368 @code{ess-execute-in-process-buffer} for that command, i.e. the output
1369 will be displayed in the process buffer if it usually goes to a
1370 temporary buffer, and vice-versa.  These are the hot keys that behave in
1371 this way:
1372
1373 @itemize @bullet
1374 @item
1375 @kbd{C-c C-x} (@code{ess-execute-objects}) @*
1376 @pindex ess-execute-objects
1377 Sends the @code{objects()}
1378 @pindex objects()
1379 command to the ESS process.  A prefix argument specifies the
1380 position on the search list (use a negative argument to toggle
1381 @code{ess-execute-in-process-buffer} as well).  A quick way to see what
1382 objects are in your working directory.
1383 @cindex objects
1384 @pindex objects()
1385
1386 @item
1387 @kbd{C-c C-s} (@code{ess-execute-search}) @*
1388 @pindex ess-execute-search
1389 Sends the @code{search()}
1390 @pindex search()
1391 command to the ESS process.
1392 @cindex search list
1393 @pindex search()
1394
1395 @item
1396 @kbd{C-c C-e} (@code{ess-execute}) @*
1397 @pindex ess-execute
1398 Prompt for an ESS expression, and evaluate it.
1399 @end itemize
1400
1401 @code{ess-execute} may seem pointless when you could just type the
1402 command in anyway, but it proves useful for `spot' calculations which
1403 would otherwise clutter your transcript, or for evaluating an expression
1404 while partway through entering a command.  You can also use this command
1405 to generate new hot keys using the Emacs keyboard macro facilities;
1406 @pxref{Keyboard Macros, Keyboard Macros, Keyboard Macros, emacs, The GNU
1407 Emacs Reference Manual}.
1408 @cindex hot keys
1409 @cindex keyboard short cuts
1410
1411 The following hot keys do not use @code{ess-execute-in-process-buffer}
1412 to decide where to display the output --- they either always display in
1413 the process buffer or in a separate buffer, as indicated:
1414
1415 @itemize @bullet
1416 @item
1417 @kbd{C-c C-a} (@code{ess-execute-attach}) @*
1418 @pindex ess-execute-attach
1419 Prompts for a directory to attach to the ESS process with the
1420 @code{attach()} command.
1421 @pindex attach()
1422 If a numeric prefix argument is given it is used as the position on the
1423 search list to attach the directory; otherwise the @Sl{} default of 2 is
1424 used.  The @code{attach()} command actually executed appears in the
1425 process buffer.
1426
1427 @item
1428 @kbd{C-c C-l} (@code{ess-load-file}) @*
1429 @pindex ess-load-file
1430 Prompts for a file to load into the ESS process using
1431 @code{source()}.  If there is an error during loading, you can jump to
1432 the error in the file with @kbd{C-x `} (@code{ess-parse-errors}).
1433 @pindex ess-parse-errors
1434 @xref{Error Checking}, for more details.
1435
1436 @item
1437 @kbd{C-c C-v} (@code{ess-display-help-on-object}) @* Pops up a help
1438 buffer for an @Sl{} object or function.  See @ref{Help} for more
1439 details.
1440
1441 @item
1442 @kbd{C-c C-q} (@code{ess-quit}) @*
1443 @cindex quitting from ESS
1444 @cindex killing the ESS process
1445 Sends the @code{q()}
1446 @pindex q()
1447 command to the ESS process (or @code{(exit)}
1448 @pindex exit()
1449 to the @b{XLS} process), and cleans up any temporary buffers (such as
1450 help buffers or edit buffers) you may have created along the way.  Use
1451 this command when you have finished your @Sl{} session instead of simply
1452 typing @code{q()} yourself, otherwise you will need to issue the command
1453 @kbd{M-x ess-cleanup}
1454 @pindex ess-cleanup
1455 @cindex cleaning up
1456 @cindex temporary buffers, killing
1457 @cindex killing temporary buffers
1458 command explicitly to make sure that all the files that need to be saved
1459 have been saved, and that all the temporary buffers have been killed.
1460 @end itemize
1461
1462 @comment  node-name,  next,  previous,  up
1463 @node Statistical Process running in ESS?, Emacsclient, Hot keys, Entering commands
1464 @section Is the Statistical Process running under ESS?
1465
1466 @cindex STERM
1467 @pindex STERM
1468 For the S languages (S, S-Plus, R) ESS sets an option in the current
1469 process that programs in the language can check to determine the
1470 environment in which they are currently running.
1471
1472 ESS sets
1473 @code{options(STERM="iESS")} for S language processes running in an
1474 inferior @code{iESS[S]} or @code{iESS[R]} buffer.
1475
1476 ESS sets
1477 @code{options(STERM="ddeESS")} for independent S-Plus for Windows
1478 processes running in the GUI and communicating with ESS via
1479 the DDE (Microsoft Dynamic Data Exchange) protocol through a
1480 @code{ddeESS[S]} buffer.
1481
1482 Other values of @code{options()$STERM} that we recommend are:
1483
1484 @itemize @bullet
1485 @item @code{length}:     Fixed length xterm or telnet window.
1486 @item @code{scrollable}: Unlimited length xterm or telnet window.
1487 @item @code{server}:     S-Plus Stat Server.
1488 @item @code{BATCH}:      BATCH.
1489 @item @code{Rgui}:       R GUI.
1490 @item @code{Commands}:   S-Plus GUI without DDE interface to ESS.
1491 @end itemize
1492
1493 Additional values may be recommended in the future as new interaction
1494 protocols are created.  Unlike the values @code{iESS} and @code{ddeESS},
1495 ESS can't set these other values since the S language program is not
1496 under the control of ESS.
1497
1498 @comment  node-name,  next,  previous,  up
1499 @node Emacsclient, Other, Statistical Process running in ESS?, Entering commands
1500 @section Using emacsclient
1501
1502 @cindex emacsclient
1503
1504 When starting R or S under Unix, ESS sets
1505 @code{options(editor="emacsclient")}.  (Under Microsoft Windows, it will
1506 use gnuclient.exe rather than emacsclient, but the same principle
1507 applies.)  Within your R session, for example, if you have a function
1508 called @code{iterator}, typing @code{fix(iterator)}, will show that
1509 function in a temporary Emacs buffer.  You can then correct the
1510 function.  When you kill the buffer, the definition of the function is
1511 updated.  Using @code{edit()} rather than @code{fix()} means that the
1512 function is not updated.  Finally, the S function @code{page(x)} will
1513 also show a text representation of the object @code{x} in a temporary
1514 Emacs buffer.
1515
1516
1517 @comment  node-name,  next,  previous,  up
1518 @node Other,  , Emacsclient, Entering commands
1519 @section Other commands provided by inferior-ESS
1520
1521 The following commands are also provided in the process buffer:
1522
1523 @itemize @bullet
1524 @item
1525 @kbd{C-c C-c} (@code{comint-interrupt-subjob}) @*
1526 @pindex comint-interrupt-subjob
1527 Sends a Control-C signal to the ESS process.  This has the effect of
1528 @cindex aborting S commands
1529 @cindex interrupting S commands
1530 aborting the current command.
1531
1532 @item
1533 @kbd{C-c C-z} (@code{ess-abort}) @*
1534 @pindex ess-abort
1535 @pindex comint-stop-subjob
1536 Sends a STOP signal to the ESS process, killing it immediately.
1537 It's not a good idea to use this, in general: Neither @code{q()} nor
1538 @code{.Last} will be executed and device drivers will not finish
1539 cleanly.  This command is provided as a safety to
1540 @code{comint-stop-subjob}, which is usually bound to @kbd{C-c C-z}.  If
1541 you want to quit from S, use @kbd{C-c C-q} (@code{ess-quit}) instead.
1542 @pindex ess-quit
1543 @cindex aborting the ESS process
1544
1545 @item
1546 @kbd{C-c C-d} (@code{ess-dump-object-into-edit-buffer}) @*
1547 @pindex ess-dump-object-into-edit-buffer
1548 Prompts for an object to be edited in an edit buffer.  @xref{Editing}.
1549 @end itemize
1550
1551 Other commands available in Inferior @Sl{} mode are discussed in
1552 @ref{Shell Mode,,, emacs, The Gnu Emacs Reference Manual}.
1553
1554 @comment  node-name,  next,  previous,  up
1555 @node Transcript Mode, ESS for the S family, Entering commands, Top
1556 @chapter Manipulating saved transcript files
1557
1558 Inferior @Sl{} mode records the transcript (the list of all commands
1559 executed, and their output) in the process buffer, which can be saved as
1560 a @dfn{transcript file}, which should normally have the suffix
1561 @file{.St}.  The most obvious use for a transcript file is as a static
1562 record of the actions you have performed in a particular @Sl{} session.
1563 Sometimes, however, you may wish to re-execute commands recorded in the
1564 transcript file by submitting them to a running ESS process.  This
1565 is what Transcript Mode is for.
1566
1567 If you load file a with the suffix @file{.St} into Emacs, it is placed
1568 in S Transcript Mode.  Transcript Mode is similar to Inferior @Sl{} mode
1569 (@pxref{Entering commands}):
1570 @cindex transcript mode motion
1571 @cindex motion in transcript mode
1572 paragraphs are defined as a command and its output, and you can move
1573 though commands either with the paragraph commands or with @kbd{C-c C-p}
1574 and @kbd{C-c C-n}.
1575
1576 @menu
1577 * Resubmit::                    Resubmitting commands from the transcript file
1578 * Clean::                       Cleaning transcript files
1579 @end menu
1580
1581 @comment  node-name,  next,  previous,  up
1582 @node Resubmit, Clean, Transcript Mode, Transcript Mode
1583 @section Resubmitting commands from the transcript file
1584
1585 Three commands are provided to re-submit command lines from the
1586 transcript file to a running ESS process.  They are:
1587
1588 @itemize @bullet
1589 @item
1590 @kbd{RET} (@code{ess-transcript-send-command}) @*
1591 Send the current command line to the ESS process, and execute it.
1592 @pindex ess-transcript-send-command
1593
1594 @item
1595 @kbd{C-c RET} (@code{ess-transcript-copy-command}) @*
1596 Copy the current command to the ESS process, and switch to the
1597 ESS process buffer (ready to edit the copied command).
1598 @pindex ess-transcript-copy-command
1599
1600 @item
1601 @kbd{M-RET} (@code{ess-transcript-send-command-and-move}) @*
1602 Send the current command to the ESS process, and move to the next
1603 command line.  This command is useful for submitting a series of
1604 commands.
1605 @end itemize
1606
1607 @noindent
1608 Note that these commands are similar to those on the same keys in
1609 Inferior @Sl{} Mode.  In all three cases, the commands should be
1610 executed when the cursor is on a command line in the transcript; the
1611 prompt is automatically removed before the command is submitted.
1612
1613 @comment  node-name,  next,  previous,  up
1614 @node Clean,  , Resubmit, Transcript Mode
1615 @section Cleaning transcript files
1616
1617 Yet another use for transcript files is to extract the command lines for
1618 inclusion in an @Sl{} source file or function.  Transcript mode provides
1619 one command which does just this:
1620
1621 @itemize @bullet
1622 @item
1623 @kbd{C-c C-w} (@code{ess-transcript-clean-region}) @*
1624 Deletes all prompts and command output in the region, leaving only the
1625 commands themselves.
1626 @end itemize
1627
1628 @noindent
1629 The remaining command lines may then be copied to a source file or edit
1630 buffer for inclusion in a function definition, or may be evaluated
1631 directly (@pxref{Evaluating code}) using the code evaluation commands
1632 from @Sl{} mode, also available in @Sl{} Transcript Mode.
1633
1634
1635 @comment  node-name,  next,  previous,  up
1636 @node ESS for the S family, Editing, Transcript Mode, Top
1637 @chapter ESS for the S family
1638 @menu
1639 * ESS(S)--Editing files::
1640 * iESS(S)--Inferior ESS processes::
1641 * ESS-help--assistance with viewing help::
1642 * Philosophies for using ESS(S)::
1643 * Scenarios for use (possibilities--based on actual usage)::
1644 * Customization Examples and Solutions to Problems::
1645 @end menu
1646 @include help-s.texi
1647
1648 @comment  node-name,  next,  previous,  up
1649 @node Editing, Editing R documentation files, ESS for the S family, Top
1650 @chapter Editing S functions
1651
1652 @cindex editing functions
1653 ESS provides facilities for editing @Sl{} objects within your Emacs
1654 session.  Most editing is performed on @Sl{} functions, although in
1655 theory you may edit datasets as well.  Edit buffers are always
1656 associated with files, although you may choose to make these files
1657 temporary if you wish.  Alternatively, you may make use of a simple yet
1658 powerful mechanism for maintaining backups of text representations of
1659 @Sl{} functions.  Error-checking is performed when @Sl{} code is loaded
1660 into the ESS process.
1661
1662 @menu
1663 * Edit buffer::                 Edit objects in a specialized buffer
1664 * Loading::                     Loading source files into the ESS process
1665 * Error Checking::              Detecting errors in source files
1666 * Evaluating code::             Sending code to the ESS process
1667 * Indenting::                   Indenting and formatting S code
1668 * Other edit buffer commands::  Commands for motion, completion and more
1669 * Source Files::                Maintaining @Sl{} source files
1670 * Source Directories::          Names and locations of dump files
1671 @end menu
1672
1673 @comment  node-name,  next,  previous,  up
1674 @node Edit buffer, Loading, Editing, Editing
1675 @section Creating or modifying S objects
1676 @cindex edit buffer
1677
1678 To edit an @Sl{} object, type
1679
1680 @itemize @bullet
1681 @item
1682 @kbd{C-c C-d} (@code{ess-dump-object-into-edit-buffer}) @*
1683 @pindex ess-dump-object-into-edit-buffer
1684 Edit an @Sl{} object in its own edit buffer.
1685 @end itemize
1686
1687 from within the ESS process buffer (@code{*S*}).  You will then be
1688 prompted for an object to edit: you may either type in the name of an
1689 existing object (for which completion is available using the @kbd{TAB}
1690 key),
1691 @cindex completion, when prompted for object names
1692 or you may enter the name of a new object.
1693 @cindex creating new objects
1694 @cindex new objects, creating
1695 A buffer will be created containing the text representation of the
1696 requested object or, if you entered the name of a non-existent object at
1697 the prompt and the variable @code{ess-function-template}
1698 @vindex ess-function-template
1699 is non-@code{nil}, you will be presented with a template defined by that
1700 variable, which defaults to a skeleton function construct.
1701
1702 You may then edit the function as required.  The edit buffer generated
1703 by @code{ess-dump-object-into-edit-buffer} is placed in the @code{ESS}
1704 major mode which provides a number of commands to facilitate editing
1705 @Sl{} source code.  Commands are provided to intelligently indent @Sl{}
1706 code, evaluate portions of @Sl{} code and to move around @Sl{} code
1707 constructs.
1708
1709 @cindex dump files
1710 @cindex reverting function definitions
1711 Note: when you dump a file with @kbd{C-c C-d}, ESS first checks
1712 to see whether there already exists an edit buffer containing that
1713 object and, if so, pops you directly to that buffer.  If not, ESS next
1714 checks whether there is a file in the appropriate place with the
1715 appropriate name (@pxref{Source Files}) and if so, reads in that file.
1716 You can use this facility to return to an object you were editing in a
1717 previous session (and which possibly was never loaded to the @Sl{}
1718 session).  Finally, if both these tests fail, the ESS process is
1719 consulted and a @code{dump()} command issued.
1720 @pindex dump()
1721 If you want to force ESS to ask the ESS process for the object's
1722 definition (say, to reformat an unmodified buffer or to revert back to
1723 S's idea of the object's definition) pass a prefix argument to
1724 @code{ess-dump-object-into-edit-buffer} by typing @kbd{C-u C-c C-d}.
1725
1726 @comment  node-name,  next,  previous,  up
1727 @node Loading, Error Checking, Edit buffer, Editing
1728 @section Loading source files into the ESS process
1729
1730 The best way to get information --- particularly function definitions
1731 --- into @Sl{} is to load them in as source file, using S's
1732 @code{source} function.  You have already seen how to create source
1733 files using @kbd{C-c C-d}; ESS provides a complementary command for
1734 loading source files (even files not created with ESS!) into the ESS
1735 process:
1736
1737 @itemize @bullet
1738 @item
1739 @kbd{C-c C-l} (@code{ess-load-file}) @*
1740 @pindex ess-load-file
1741 Loads a file into the ESS process using @code{source()}.
1742 @pindex source()
1743 @end itemize
1744
1745 @noindent
1746 After typing @kbd{C-c C-l} you will prompted for the name of the file to
1747 load into S; usually this is the current buffer's file which is the
1748 default value (selected by simply pressing @kbd{RET} at the prompt).
1749 You will be asked to save the buffer first if it has been modified (this
1750 happens automatically if the buffer was generated with @kbd{C-c C-d}).
1751 The file will then be loaded, and if it loads successfully you will be
1752 returned to the ESS process.
1753
1754 @comment  node-name,  next,  previous,  up
1755 @node Error Checking, Evaluating code, Loading, Editing
1756 @section Detecting errors in source files
1757 @cindex errors
1758 @cindex parsing errors
1759 If any errors occur when loading a file with @code{C-c C-l}, ESS will
1760 inform you of this fact.  In this case, you can jump directly to the
1761 line in the source file which caused the error by typing @kbd{C-x `}
1762 (@code{ess-parse-errors}).
1763 @pindex ess-parse-errors
1764 You will be returned to the offending file (loading it into a buffer if
1765 necessary) with point at the line @Sl{} reported as containing the
1766 error.  You may then correct the error, and reload the file.  Note that
1767 none of the commands in an @Sl{} source file will take effect if any
1768 part of the file contains errors.
1769
1770 Sometimes the error is not caused by a syntax error (loading a
1771 non-existent file for example). In this case typing @kbd{C-x `} will
1772 simply display a buffer containing S's error message.  You can force
1773 this behavior (and avoid jumping to the file when there @emph{is} a
1774 syntax error) by passing a prefix argument to @code{ess-parse-errors}
1775 with @kbd{C-u C-x `}.
1776
1777 @comment  node-name,  next,  previous,  up
1778 @node Evaluating code, Indenting, Error Checking, Editing
1779 @section Sending code to the ESS process
1780
1781 Other commands are also available for evaluating portions of code in the
1782 S process.  These commands cause the selected code to be evaluated
1783 directly by the ESS process as if you had typed them in at the
1784 command line; the @code{source()} function is not used.  You may choose
1785 whether both the commands and their output appear in the process buffer
1786 (as if you had typed in the commands yourself) or if the output alone is
1787 echoed.  The behavior is controlled by the variable
1788 @code{ess-eval-visibly-p} whose default is @code{nil}
1789 @vindex ess-eval-visibly-p
1790 (display output only).  Passing a prefix argument (@kbd{C-u}) to any of
1791 the following commands, however, reverses the meaning of
1792 @code{ess-eval-visibly-p} for that command only --- for example @kbd{C-u
1793 C-c C-j} echoes the current line of S (or other) code in the ESS
1794 process buffer, followed by its output.  This method of evaluation is an
1795 alternative to S's @code{source()} function
1796 @pindex source()
1797 @cindex echoing commands when evaluating
1798 @cindex evaluating code with echoed commands
1799 when you want the input as well as the output to be displayed.  (You can
1800 sort of do this with @code{source()} when the option @code{echo=T} is
1801 set, except that prompts do not get displayed.  ESS puts prompts in the
1802 right places.) The commands for evaluating code are:
1803
1804 @itemize @bullet
1805 @cindex evaluating S expressions
1806 @item
1807 @kbd{C-c C-j} (@code{ess-eval-line}) @*
1808 @pindex ess-eval-line
1809 Send the line containing point to the ESS process.
1810
1811 @item
1812 @kbd{C-c M-j} (@code{ess-eval-line-and-go}) @*
1813 @pindex ess-eval-line-and-go
1814 As above, but returns you to the ESS process buffer as well.
1815
1816 @item
1817 @kbd{C-c C-f} or @kbd{ESC C-x} (aka @kbd{M-C-x}) (@code{ess-eval-function}) @*
1818 @pindex ess-eval-function
1819 Send the @Sl{} function containing point to the ESS process.
1820
1821 @item
1822 @kbd{C-c M-f} (@code{ess-eval-function-and-go}) @*
1823 @pindex ess-eval-function-and-go
1824 As above, but returns you to the ESS process buffer as well.
1825
1826 @item
1827 @kbd{C-c C-r} (@code{ess-eval-region}) @*
1828 @pindex ess-eval-region
1829 Send the text between point and mark to the ESS process.
1830
1831 @item
1832 @kbd{C-c M-r} (@code{ess-eval-region-and-go}) @*
1833 @pindex ess-eval-region-and-go
1834 As above, but returns you to the ESS process buffer as well.
1835
1836 @item
1837 @kbd{C-c C-b} (@code{ess-eval-buffer}) @*
1838 @pindex ess-eval-buffer
1839 Send the contents of the edit buffer to the ESS process.
1840
1841 @item
1842 @kbd{C-c M-b} (@code{ess-eval-buffer-and-go}) @*
1843 @pindex ess-eval-function-and-go
1844 As above, but returns you to the ESS process buffer as well.
1845
1846 @item
1847 @kbd{C-c C-n} (@code{ess-eval-line-and-step}) @*
1848 @pindex ess-eval-line-and-step
1849 @cindex stepping through code
1850 @cindex debugging S functions
1851 Sends the current line to the ESS process, echoing it in the process
1852 buffer, and moves point to the next line.  Useful when debugging for
1853 stepping through your code.
1854 @end itemize
1855
1856 It should be stressed once again that these @code{ess-eval-} commands
1857 should only be used for evaluating small portions of code for debugging
1858 purposes, or for generating transcripts from source files.  When editing
1859 S functions, @kbd{C-c C-l} is the command to use to update the
1860 function's value.  In particular, @code{ess-eval-buffer} is now largely
1861 obsolete.
1862
1863 One final command is provided for spot-evaluations of @Sl{} code:
1864
1865 @itemize @bullet
1866 @kbd{C-c C-t} (@code{ess-execute-in-tb}) @*
1867 @pindex ess-execute-in-tb
1868 Prompt for an @Sl{} expression and evaluate it.  Displays result in a
1869 temporary buffer.
1870 @end itemize
1871
1872 @noindent
1873 This is useful for quick calculations, etc.
1874
1875 All the above commands are useful for evaluating small amounts of code
1876 and observing the results in the process buffer.  A useful way to work
1877 is to divide the frame into two windows; one containing the source code
1878 and the other containing the process buffer.  If you wish to make the
1879 process buffer scroll automatically when the output reaches the bottom
1880 of the window, you will need to set the variable
1881 @code{comint-scroll-to-bottom-on-output} to @code{'others} or @code{t}.
1882
1883
1884 @comment  node-name,  next,  previous,  up
1885 @node Indenting, Other edit buffer commands, Evaluating code, Editing
1886 @section Indenting and formatting S code
1887
1888 ESS now provides a sophisticated mechanism for indenting @Sl{} source
1889 code (thanks to Ken'ichi Shibayama).  Compound statements (delimited by
1890 @samp{@{} and @samp{@}}) are indented relative to their enclosing block.
1891 In addition, the braces have been electrified to automatically indent to
1892 the correct position when inserted, and optionally insert a newline at
1893 the appropriate place as well.  Lines which continue an incomplete
1894 expression are indented relative to the first line of the expression.
1895 Function definitions, @code{if} statements, calls to @code{expression()}
1896 and loop constructs are all recognized and indented appropriately.  User
1897 variables are provided to control the amount if indentation in each
1898 case, and there are also a number of predefined indentation styles to
1899 choose from.
1900
1901 @cindex comments in S
1902 Comments are also handled specially by ESS, using an idea borrowed from
1903 the Emacs-Lisp indentation style.  By default,
1904 comments beginning with @samp{###}
1905 are aligned to the beginning of the line.  Comments beginning with
1906 @samp{##} are aligned to the current level of indentation for the block
1907 containing the comment.  Finally, comments beginning with @samp{#} are
1908 aligned to a column on the right (the 40th column by default, but this
1909 value is controlled by the variable @code{comment-column},)
1910 @vindex comment-column
1911 or just after the expression on the line containing the comment if it
1912 extends beyond the indentation column.  You turn off the default
1913 behavior by adding the line
1914 @code{(setq ess-fancy-comments nil)} to your @file{.emacs} file.
1915 @vindex ess-fancy-comments
1916
1917 The indentation commands provided by ESS are:
1918 @cindex indenting
1919 @cindex formatting source code
1920
1921 @itemize @bullet
1922 @item
1923 @kbd{TAB} (@code{ess-indent-command}) @*
1924 Indents the current line as @Sl{} code.  If a prefix argument is given,
1925 all following lines which are part of the same (compound) expression are
1926 indented by the same amount (but relative indents are preserved).
1927
1928 @item
1929 @kbd{LFD} (@code{newline-and-indent}) @*
1930 Insert a newline, and indent the next line.  (Note: if your keyboard
1931 does not have a @key{LINEFEED} key, you can use @kbd{C-j} instead.)
1932 Some people prefer to bind @key{RET} to this command.
1933
1934 @item
1935 @kbd{ESC C-q} aka @kbd{M-C-q} aka @kbd{C-M-q} (@code{ess-indent-exp}) @*
1936 Indents each line in the @Sl{} (compound) expression which follows point.
1937 Very useful for beautifying your @Sl{} code.
1938
1939 @item
1940 @kbd{@{} and @kbd{@}} (@code{ess-electric-brace}) @*
1941 The braces automatically indent to the correct position when typed.
1942
1943 @item
1944 @kbd{M-;} (@code{indent-for-comment}) @*
1945 Indents an existing comment line appropriately, or inserts an
1946 appropriate comment marker.
1947
1948 @item
1949 @kbd{M-x ess-set-style} @*
1950 Set the formatting style in this buffer to be one of the predefined
1951 styles: @code{GNU}, @code{BSD}, @code{K&R}, @code{CLB}, and @code{C++}.
1952 The @code{DEFAULT} style uses the default values for the indenting
1953 variables (unless they have been modified in your @file{.emacs} file.)
1954 @cindex @file{.emacs} file
1955 This command causes all of the formatting variables to be buffer-local.
1956 @end itemize
1957
1958 @comment  node-name,  next,  previous,  up
1959 @node Other edit buffer commands, Source Files, Indenting, Editing
1960 @section Commands for motion, completion and more
1961
1962 A number of commands are provided to move across function definitions
1963 in the edit buffer:
1964 @itemize @bullet
1965 @item
1966 @kbd{ESC C-a} aka @kbd{C-M-a} (@code{ess-beginning-of-function}) @*
1967 @pindex ess-beginning-of-function
1968 Moves point to the beginning of the function containing point.
1969
1970 @item
1971 @kbd{ESC C-e} aka @kbd{C-M-e} (@code{ess-end-of-function}) @*
1972 @pindex ess-end-of-function
1973 Moves point to the end of the function containing point.
1974
1975 @item
1976 @kbd{ESC C-h} aka @kbd{C-M-h} (@code{ess-mark-function}) @*
1977 Places point at the beginning of the @Sl{} function containing point, and
1978 mark at the end.
1979 @end itemize
1980 @noindent
1981 Don't forget the usual Emacs commands for moving over balanced
1982 expressions and parentheses: @xref{Lists, Lists and Sexps, Lists and
1983 Sexps, Emacs, The GNU Emacs Reference Manual}.
1984
1985 @cindex completion in edit buffer
1986 Completion is provided in the edit buffer in a similar fashion to the
1987 process buffer: @kbd{M-TAB} completes file names and @kbd{M-?} lists
1988 file completions.  Since @key{TAB} is used for indentation in the edit
1989 buffer, object completion is now performed with @kbd{C-c TAB}.  Note
1990 however that completion is only provided over globally known S objects
1991 (such as system functions) --- it will @emph{not} work for arguments to
1992 functions or other variables local to the function you are editing.
1993
1994 Finally, two commands are provided for returning to the ESS process buffer:
1995
1996 @itemize @bullet
1997 @item
1998 @kbd{C-c C-z} (@code{ess-switch-to-end-of-ESS}) @*
1999 @pindex ess-switch-to-end-of-ESS
2000 Returns you to the ESS process buffer, placing point at the end of the
2001 buffer.
2002
2003 @item
2004 @kbd{C-c C-y} (@code{ess-switch-to-ESS}) @*
2005 @pindex ess-switch-to-ESS
2006 Also returns to to the ESS process buffer, but leaves point where it was.
2007 @end itemize
2008
2009 In addition some commands available in the process buffer are also
2010 available in the edit buffer.  You can still read help files with
2011 @kbd{C-c C-v}, edit another function with @kbd{C-c C-d} and of course
2012 @kbd{C-c C-l} can be used to load a source file into S.  @xref{Other},
2013 for more details on these commands.
2014
2015 @comment  node-name,  next,  previous,  up
2016 @node Source Files, Source Directories, Other edit buffer commands, Editing
2017 @section Maintaining S source files
2018
2019 Every edit buffer in ESS is associated with a @dfn{dump file} on disk.
2020 Dump files are created whenever you type @kbd{C-c C-d}
2021 (@code{ess-dump-object-into-edit-buffer}), and may either be deleted
2022 after use, or kept as a backup file or as a means of keeping several
2023 versions of an @Sl{} function.
2024 @cindex dump files
2025
2026 @defvr {User Option} ess-delete-dump-files
2027 If non-@code{nil}, dump files created with C-c C-d are deleted
2028 immediately after they are created by the ess-process.
2029 @end defvr
2030
2031 Since immediately after @Sl{} dumps an object's definition to a disk
2032 file the source code on disk corresponds exactly to S's idea of the
2033 object's definition, the disk file isn't needed; deleting it now has the
2034 advantage that if you @emph{don't} modify the file (say, because you
2035 just wanted to look at the definition of one of the standard S
2036 functions) the source dump file won't be left around when you kill the
2037 buffer.  Note that this variable only applies to files generated with
2038 S's @code{dump} function; it doesn't apply to source files which already
2039 exist.  The default value is @code{t}.
2040
2041 @defvr {User Option} ess-keep-dump-files
2042 Option controlling what to do with the dump file after an object has
2043 been successfully loaded into S.  Valid values are @code{nil} (always
2044 delete), @code{ask} (always ask whether to delete), @code{check} (delete
2045 files generated with @kbd{C-c C-d} in this Emacs session, otherwise ask
2046 --- this is the default) and @code{t} (never delete).  This variable is
2047 buffer-local.
2048 @end defvr
2049
2050 After an object has been successfully (i.e. without error) loaded
2051 back into @Sl{} with @kbd{C-c C-l}, the disk file again corresponds
2052 exactly (well, almost --- see below) to S's record of the object's
2053 definition, and so some people prefer to delete the disk file rather
2054 than unnecessarily use up space.  This option allows you to do just
2055 that.
2056
2057 @cindex comments
2058 @cindex project work in S
2059 @cindex historic backups
2060 If the value of @code{ess-keep-dump-files} is @code{t}, dump files are
2061 never deleted after they are loaded.  Thus you can maintain a complete
2062 text record of the functions you have edited within ESS.  Backup files
2063 are kept as usual, and so by using the Emacs numbered backup facility ---
2064 @pxref{Backup Names, Single or Numbered Backups, Single or Numbered
2065 Backups, emacs, The Gnu Emacs Reference Manual}, you can keep a historic
2066 record of function definitions.  Another possibility is to maintain the
2067 files with a version-control system such as RCS @xref{Version Control,
2068 Version Control, Version Control, emacs, The Gnu Emacs Reference
2069 Manual}.  As long as a dump file exists in the appropriate place for a
2070 particular object, editing that object with @kbd{C-c C-d} finds that
2071 file for editing (unless a prefix argument is given) --- the ESS
2072 process is not consulted.  Thus you can keep comments @emph{outside} the
2073 function definition as a means of documentation that does not clutter
2074 the @Sl{} object itself.  Another useful feature is that you may format
2075 the code in any fashion you please without @Sl{} re-indenting the code
2076 every time you edit it.  These features are particularly useful for
2077 project-based work.
2078
2079 If the value of @code{ess-keep-dump-files} is nil, the dump file is always
2080 silently deleted after a successful load with @kbd{C-c C-l}.  While this
2081 is useful for files that were created with @kbd{C-c C-d} it also applies
2082 to any other file you load (say, a source file of function
2083 definitions), and so can be dangerous to use unless you are careful.
2084 Note that since @code{ess-keep-dump-files} is buffer-local, you can make
2085 sure particular files are not deleted by setting it to @code{t} in the
2086 Local Variables section of the file @xref{File Variables, Local
2087 Variables in Files, Local Variables in Files, emacs, The Gnu Emacs
2088 Reference Manual}.
2089
2090 A safer option is to set @code{ess-keep-dump-files} to @code{ask}; this
2091 means that ESS will always ask for confirmation before deleting the
2092 file.  Since this can get annoying if you always want to delete dump
2093 files created with @code{C-c C-d}, but not any other files, setting
2094 @code{ess-keep-dump-files} to @code{check} (the default value) will
2095 silently delete dump files created with @kbd{C-c C-d} in the current
2096 Emacs session, but query for any other file.  Note that in any case you
2097 will only be asked for confirmation once per file, and your answer is
2098 remembered for the rest of the Emacs session.
2099
2100 Note that in all cases, if an error (such as a syntax error) is detected
2101 while loading the file with @kbd{C-c C-l}, the dump file is @emph{never}
2102 deleted.  This is so that you can edit the file in a new Emacs session
2103 if you happen to quit Emacs before correcting the error.
2104
2105 @cindex autosaving
2106 Dump buffers are always autosaved, regardless of the value of
2107 @code{ess-keep-dump-files}.
2108
2109 @comment  node-name,  next,  previous,  up
2110 @node Source Directories,  , Source Files, Editing
2111 @section Names and locations of dump files
2112
2113 @cindex dump file names
2114 Every dump file should be given a unique file name, usually the dumped
2115 object name with some additions.
2116
2117 @defvr {User Option} ess-dump-filename-template
2118 Template for filenames of dumped objects.  @code{%s} is replaced by the
2119 object name.
2120 @end defvr
2121
2122 @noindent
2123 By default, dump file names are the user name, followed by @samp{.} and
2124 the object and ending with @samp{.S}.  Thus if user @code{joe} dumps the
2125 object @code{myfun} the dump file will have name @file{joe.myfun.S}.
2126 The username part is included to avoid clashes when dumping into a
2127 publicly-writable directory, such as @file{/tmp}; you may wish to remove
2128 this part if you are dumping into a directory owned by you.
2129
2130 @cindex dump file directories
2131 You may also specify the directory in which dump files are written:
2132
2133 @defvr {User Option} ess-source-directory
2134 Directory name (ending in a slash) where @Sl{} dump files are to be written.
2135 @end defvr
2136
2137 By default, dump files are always written to @file{/tmp}, which is fine
2138 when @code{ess-keep-dump-files} is @code{nil}.  If you are keeping dump
2139 files, then you will probably want to keep them somewhere in your home
2140 directory, say @file{~/S-source}.  This could be achieved by including
2141 the following line in your @file{.emacs} file:
2142 @cindex @file{.emacs} file
2143 @example
2144 (setq ess-source-directory (expand-file-name "~/S-source/"))
2145 @end example
2146
2147 If you would prefer to keep your dump files in separate directories
2148 depending on the value of some variable, ESS provides a facility for
2149 this also.  By setting @code{ess-source-directory} to a lambda
2150 expression which evaluates to a directory name, you have a great deal of
2151 flexibility in selecting the directory for a particular source file to
2152 appear in.  The lambda expression is evaluated with the process buffer
2153 as the current buffer and so you can use the variables local to that
2154 buffer to make your choice.  For example, the following expression
2155 causes source files to be saved in the subdirectory @file{Src} of the
2156 directory the ESS process was run in.
2157
2158 @example
2159 (setq ess-source-directory
2160       (lambda ()
2161          (concat ess-directory "Src/")))
2162 @end example
2163
2164 @noindent
2165 @vindex ess-directory
2166 (@code{ess-directory} is a buffer-local variable in process buffers
2167 which records the directory the ESS process was run from.)  This is
2168 useful if you keep your dump files and you often edit objects with the
2169 same name in different ESS processes.  Alternatively, if you often
2170 change your @Sl{} working directory during an @Sl{} session, you may
2171 like to keep dump files in some subdirectory of the directory pointed to
2172 by the first element of the current search list.  This way you can edit
2173 objects of the same name in different directories during the one S
2174 session:
2175 @cindex search list
2176 @cindex working directory
2177 @example
2178 (setq ess-source-directory
2179    (lambda ()
2180        (file-name-as-directory
2181         (expand-file-name (concat
2182                            (car ess-search-list)
2183                            "/.Src")))))
2184 @end example
2185 @vindex ess-search-list
2186
2187 If the directory generated by the lambda function does not exist but can
2188 be created, you will be asked whether you wish to create the directory.
2189 If you choose not to, or the directory cannot be created, you will not
2190 be able to edit functions.
2191
2192 @node Editing R documentation files, Help, Editing, Top
2193 @chapter Editing R documentation files
2194
2195 ESS also provides support for editing @dfn{R documentation} (``Rd'')
2196 files.  @R{} objects are documented in files written in Rd format, a
2197 simple markup language closely resembling (La)@TeX{}, which can be
2198 processed into a variety of formats, including La@TeX{}, @acronym{HTML},
2199 and plain text.  Rd format is described in section ``Rd format'' of the
2200 ``Writing R Extensions'' manual in the R distribution.
2201
2202 Visiting an Rd file as characterized by its extension @file{Rd} will
2203 activate Rd Mode, which provides several facilities for making editing R
2204 documentation files more convenient, by helping with indentation,
2205 insertions, even doing some of the typing for you (with Abbrev Mode),
2206 and by showing Rd keywords, strings, etc.@: in different faces (with
2207 Font Lock Mode).
2208
2209 Note that R also accepts Rd files with extension @file{rd}; to activate
2210 ESS[Rd] support for this extension, you may need to add
2211
2212 @example
2213 (add-to-list 'auto-mode-alist '("\\.rd\\'" . Rd-mode))
2214 @end example
2215
2216 @noindent
2217 to one of your Emacs startup files.
2218
2219 In Rd mode, the following special Emacs commands can be used in addition
2220 to the standard Emacs commands.
2221
2222 @table @kbd
2223 @item C-h m
2224 Describe the features of Rd mode.
2225
2226 @item LFD
2227 @itemx RET
2228 Reindent the current line, insert a newline and indent the new line
2229 (@code{reindent-then-newline-and-indent}).  An abbrev before point is
2230 expanded if @code{abbrev-mode} is non-@code{nil}.
2231
2232 @item TAB
2233 Indent current line based on its contents and on previous lines
2234 (@code{indent-according-to-mode}).
2235
2236 @item C-c C-e
2237 Insert a ``skeleton'' with Rd markup for at least all mandatory entries
2238 in Rd files (@code{Rd-mode-insert-skeleton}).  Note that many users
2239 might prefer to use the R function @code{prompt} on an existing R object
2240 to generate a non-empty Rd ``shell'' documenting the object (which
2241 already has all information filled in which can be obtained from the
2242 object).
2243
2244 @item C-c C-f
2245 Insert ``font'' specifiers for some of the Rd markup commands markup
2246 available for emphasizing or quoting text, including markup for URLs and
2247 email addresses (@code{Rd-font}).  @kbd{C-c C-f} is only a prefix; see
2248 e.g.@: @kbd{C-c C-f TAB} for the available bindings.  Note that
2249 currently, not all of the Rd text markup as described in section
2250 ``Marking text'' of ``Writing R Extensions'' can be accessed via
2251 @kbd{C-c C-f}.
2252
2253 @item C-c C-j
2254 Insert a suitably indented  @samp{\item@{} on the next line
2255 (@code{Rd-mode-insert-item}).
2256
2257 @item C-c C-p
2258 Preview a plain text version (``help file'', @pxref{Help}) generated
2259 from the Rd file (@code{Rd-preview-help}).
2260 @end table
2261
2262 In addition, when editing Rd files one can interact with a running R
2263 process in a similar way as when editing R language files.  E.g.,
2264 @kbd{C-c C-v} provides access to on-line help, and @kbd{C-c C-n} sends
2265 the current line to the R process for evaluation.  This interaction is
2266 particularly useful when editing the examples in the Rd file.  See
2267 @kbd{C-h m} for all available commands.
2268
2269 Rd mode also provides access to abbreviations for most of the Rd markup
2270 commands.  Type @kbd{M-x list-abbrevs} with Abbrev mode turned on to
2271 list all available abbrevs.  Note that all Rd abbrevs start with a grave
2272 accent.
2273
2274 Rd mode can be customized via the following variables.
2275
2276 @table @code
2277 @item Rd-mode-hook
2278 Hook to be run when Rd mode is entered.
2279 @item Rd-indent-level
2280 The indentation of Rd code with respect to containing blocks.  Default
2281 is 2.
2282 @item Rd-to-help-command
2283 The shell command used for converting Rd source to help text.  Default
2284 is @samp{R CMD Rd2txt}.
2285 @end table
2286
2287 To automatically turn on the abbrev and font-lock features of Rd mode,
2288 add the following lines to one of your Emacs startup files:
2289
2290 @example
2291 (add-hook 'Rd-mode-hook
2292           (lambda ()
2293            (abbrev-mode 1)
2294            (font-lock-mode 1)))
2295 @end example
2296
2297
2298 @comment  node-name,  next,  previous,  up
2299 @node Help, ESS for SAS, Editing R documentation files, Top
2300 @chapter Reading help files
2301 @cindex help files
2302
2303 ESS provides an easy-to-use facility for reading @Sl{} help files from
2304 within Emacs.  From within the ESS process buffer or any ESS edit
2305 buffer, typing @kbd{C-c C-v} (@code{ess-display-help-on-object})
2306 @pindex ess-display-help-on-object
2307 will prompt you for the name of an object for which you would like
2308 documentation.  Completion is provided over all objects which have help
2309 files.
2310
2311 If the requested object has documentation, you will be popped into a
2312 buffer (named @code{*help(@var{obj-name})*}) containing the help file.
2313 This buffer is placed in a special `S Help' mode which disables the
2314 usual editing commands but which provides a number of keys for paging
2315 through the help file:
2316
2317 @itemize @bullet
2318 Help commands:
2319
2320 @item
2321 @kbd{?} (@code{ess-describe-help-mode}) @*
2322 @pindex ess-describe-help-mode
2323 Pops up a help buffer with a list of the commands available in @Sl{} help
2324 mode.
2325
2326 @item
2327 @kbd{h} (@code{ess-display-help-on-object}) @*
2328 @pindex ess-display-help-on-object
2329 Pop up a help buffer for a different object
2330
2331 Paging commands:
2332
2333 @cindex paging commands in help buffers
2334 @item
2335 @kbd{b} or @kbd{DEL} (@code{scroll-down}) @*
2336 Move one page backwards through the help file.
2337
2338 @item
2339 @kbd{SPC} (@code{scroll-up}) @*
2340 Move one page forwards through the help file.
2341
2342 @item
2343 @kbd{>} (@code{beginning-of-buffer}) and @kbd{<} (@code{end-of-buffer})
2344 @*
2345 Move to the beginning and end of the help file, respectively.
2346
2347 Section-based motion commands:
2348
2349 @item
2350 @kbd{n} (@code{ess-skip-to-next-section}) and @kbd{p}
2351 (@code{ess-skip-to-previous-section}) @* Move to the next and previous
2352 @pindex ess-skip-to-next-section
2353 @pindex ess-skip-to-previous-section
2354 section header in the help file, respectively.  A section header
2355 consists of a number of capitalized words, followed by a colon.
2356
2357 In addition, the @kbd{s} key followed by one of the following letters
2358 will jump to a particular section in the help file:
2359 @pindex ess-skip-to-help-section
2360 @table @samp
2361 @item a
2362 ARGUMENTS:
2363
2364 @item b
2365 BACKGROUND:
2366
2367 @item B
2368 BUGS:
2369
2370 @item d
2371 DETAILS:
2372
2373 @item D
2374 DESCRIPTION:
2375
2376 @item e
2377 EXAMPLES:
2378
2379 @item n
2380 NOTE:
2381
2382 @item o
2383 OPTIONAL ARGUMENTS:
2384
2385 @item r
2386 REQUIRED ARGUMENTS:
2387
2388 @item R
2389 REFERENCES:
2390
2391 @item s
2392 SIDE EFFECTS:
2393
2394 @item s
2395 SEE ALSO:
2396
2397 @item u
2398 USAGE:
2399
2400 @item v
2401 VALUE:
2402
2403 @item <
2404 Jumps to beginning of file
2405
2406 @item >
2407 Jumps to end of file
2408
2409 @item ?
2410 Pops up a help buffer with a list of the defined section motion keys.
2411 @end table
2412
2413 Miscellaneous:
2414
2415 @item
2416 @kbd{l} (@code{ess-eval-line-and-step}) @*
2417 @pindex ess-eval-line-and-step
2418 Evaluates the current line in the ESS process, and moves to the next
2419 line.  Useful for running examples in help files.
2420
2421 @item
2422 @kbd{r} (@code{ess-eval-region}) @*
2423 @pindex ess-eval-region
2424 Send the contents of the current region to the ESS process.  Useful
2425 for running examples in help files.
2426
2427 @item
2428 @kbd{/} (@code{isearch-forward}) @*
2429 Same as @kbd{C-s}.
2430
2431 Quit commands:
2432
2433 @item
2434 @kbd{q} (@code{ess-switch-to-end-of-ESS}) @*
2435 @pindex ess-switch-to-end-of-ESS
2436 Returns to the ESS process buffer in another window, leaving the
2437 help window visible.
2438
2439 @item
2440 @kbd{k} (@code{kill-buffer}) @*
2441 Kills the help buffer.
2442
2443 @item
2444 @kbd{x} (@code{ess-kill-buffer-and-go}) @*
2445 Return to the ESS process, killing this help buffer.
2446 @end itemize
2447
2448 In addition, all of the ESS commands available in the edit buffers are
2449 also available in @Sl{} help mode (@pxref{Edit buffer}).  Of course, the
2450 usual (non-editing) Emacs commands are available, and for convenience
2451 the digits and @key{-} act as prefix arguments.
2452
2453 If a help buffer already exists for an object for which help is
2454 requested, that buffer is popped to immediately; the ESS process is
2455 not consulted at all.  If the contents of the help file have changed,
2456 you either need to kill the help buffer first, or pass a prefix argument
2457 (with @kbd{C-u}) to @code{ess-display-help-on-object}.
2458
2459 Help buffers are marked as temporary buffers in ESS, and are deleted
2460 when @code{ess-quit} or @code{ess-cleanup} are called.
2461
2462 Help buffers normally appear in another window within the current
2463 frame.  If you wish help buffers to appear in their own frame (either
2464 one per help buffer, or one for all help buffers), you can customize the
2465 variable @code{ess-help-own-frame}.
2466
2467 @pindex ess-quit
2468 @pindex ess-cleanup
2469 @cindex temporary buffers
2470
2471 @comment  node-name,  next,  previous,  up
2472 @node ESS for SAS, ESS for BUGS, Help, Top
2473 @chapter ESS for SAS
2474
2475 @menu
2476 * ESS(SAS)--Design philosophy::
2477 * ESS(SAS)--Editing files::
2478 * ESS(SAS)--TAB key::
2479 * ESS(SAS)--Batch SAS processes::
2480 * ESS(SAS)--Function keys for batch processing::
2481 * iESS(SAS)--Interactive SAS processes::
2482 * iESS(SAS)--Common problems::
2483 * ESS(SAS)--Graphics::
2484 * ESS(SAS)--MS Windows::
2485 @end menu
2486 @include help-sas.texi
2487
2488 @comment  node-name,  next,  previous,  up
2489 @node ESS for BUGS, Miscellaneous, ESS for SAS, Top
2490 @chapter ESS for BUGS
2491
2492 @menu
2493 * ESS(BUGS)--Model files::
2494 * ESS(BUGS)--Command files::
2495 * ESS(BUGS)--Log files::
2496 @end menu
2497 @include help-bugs.texi
2498
2499 @comment  node-name,  next,  previous,  up
2500 @node Miscellaneous, Mailing lists/bug reports, ESS for BUGS, Top
2501 @chapter Other features of ESS
2502
2503 ESS has a few miscellaneous features, which didn't fit anywhere else.
2504
2505 @menu
2506 * Highlighting::                Syntactic highlighting of buffers
2507 * Graphics::                    Using graphics with ESS
2508 * Imenu::                       Support for Imenu in ESS
2509 * Toolbar::                     Support for toolbar in ESS
2510 * TAGS::                        Using TAGS for S files
2511 * Rdired::                      Directory editor for R objects
2512 @end menu
2513
2514 @comment  node-name,  next,  previous,  up
2515 @node Highlighting, Graphics, Miscellaneous, Miscellaneous
2516 @section Syntactic highlighting of buffers
2517
2518 ESS provides Font-Lock (@pxref{Faces,,Using Multiple Typefaces,
2519 emacs, The Gnu Emacs Reference Manual}) patterns for Inferior @Sl{} Mode, S
2520 Mode, and @Sl{} Transcript Mode buffers.
2521 @cindex Font-lock mode
2522 @cindex highlighting
2523
2524 To activate highlighting, you need to turn on Font Lock mode in the
2525 appropriate buffers.  This can be done on a per-buffer basis with
2526 @kbd{M-x font-lock-mode}, or may be done by adding
2527 @code{turn-on-font-lock} to @code{inferior-ess-mode-hook},
2528 @code{ess-mode-hook} and @code{ess-transcript-mode-hook}.  Your systems
2529 administrator may have done this for you in @file{ess-site.el}
2530 (@pxref{Customization}).
2531
2532 The font-lock patterns are defined in three variables, which you may
2533 modify if desired:
2534
2535 @defvar inferior-ess-font-lock-keywords
2536 Font-lock patterns for Inferior ESS Mode.  The default value
2537 highlights prompts, inputs, assignments, output messages, vector and
2538 matrix labels, and literals such as @samp{NA} and @code{TRUE}.
2539 @end defvar
2540
2541 @defvar ess-mode-font-lock-keywords
2542 Font-lock patterns for ESS programming mode.  The default value
2543 highlights function names, literals, assignments, source functions and
2544 reserved words.
2545 @end defvar
2546
2547 @defvar ess-trans-font-lock-keywords
2548 Font-lock patterns for ESS Transcript Mode.  The default value
2549 highlights the same patterns as in Inferior ESS Mode.
2550 @end defvar
2551
2552 @comment  node-name,  next,  previous,  up
2553 @node Graphics, Imenu, Highlighting, Miscellaneous
2554 @section Using graphics with ESS
2555
2556 @cindex graphics
2557 One of the main features of the @code{S} package is its ability to
2558 generate high-resolution graphics plots, and ESS provides a number of
2559 features for dealing with such plots.
2560
2561 @menu
2562 * printer::                     The printer() graphics driver
2563 * X11::                         The X11() (and other X-windows based) driver
2564 * winjava::                     Java Graphics Device
2565 @end menu
2566
2567 @comment  node-name,  next,  previous,  up
2568 @node printer, X11, Graphics, Graphics
2569 @subsection Using ESS with the @code{printer()} driver
2570
2571 This is the simplest (and least desirable) method of using graphics
2572 within ESS.  S's @code{printer()} device driver produces crude character
2573 based plots which can be contained within the ESS process buffer
2574 itself.  To start using character graphics, issue the @Sl{} command
2575 @example
2576 printer(width=79)
2577 @end example
2578 @pindex printer()
2579 (the @code{width=79} argument prevents Emacs line-wrapping at column
2580 80 on an 80-column terminal.  Use a different value for a terminal with
2581 a different number of columns.) Plotting commands do not generate
2582 graphics immediately, but are stored until the @code{show()} command
2583 is issued, which displays the current figure.
2584
2585 @comment  node-name,  next,  previous,  up
2586 @node X11, winjava, printer, Graphics
2587 @subsection Using ESS with windowing devices
2588
2589 @cindex X windows
2590 Of course, the ideal way to use graphics with ESS is to use a windowing
2591 system.  Under X11, this requires that the DISPLAY environment
2592 variable be appropriately set, which may not always be the case within
2593 your Emacs process.  ESS provides a facility for setting the value of
2594 DISPLAY before the ESS process is started if the variable
2595 @code{ess-ask-about-display}
2596 @pindex ess-ask-about-display
2597 is non-@code{nil}.
2598
2599 @comment  node-name,  next,  previous,  up
2600 @node winjava,  , X11, Graphics
2601 @subsection Java Graphics Device
2602
2603 @cindex winjava
2604
2605 S+6.1 and newer on Windows contains a java library that supports graphics.  Send
2606 the commands:
2607
2608 @example
2609 library(winjava)
2610 java.graph()
2611 @end example
2612
2613 @noindent to start the graphics driver.  This allows you to use ESS for both
2614 interaction and graphics within S-PLUS.  (Thanks to Tim Hesterberg for
2615 this information.)
2616
2617 @comment  node-name,  next,  previous,  up
2618 @node Imenu, Toolbar,  Graphics, Miscellaneous
2619 @section Imenu
2620
2621 Imenu is an Emacs tool for providing mode-specific buffer indexes.  In
2622 some of the ESS editing modes (currently SAS and S), support for Imenu
2623 is provided.  For example, in S mode buffers, the menubar should display
2624 an item called "Imenu-S".  Within this menubar you will then be offered
2625 bookmarks to particular parts of your source file (such as the starting
2626 point of each function definition).
2627
2628 Imenu works by searching your buffer for lines that match what ESS
2629 thinks is the beginning of a suitable entry, e.g. the beginning of a
2630 function definition.  To examine the regular expression that ESS uses,
2631 check the value of @code{imenu-generic-expression}.  This value is set
2632 by various ESS variables such as @code{ess-imenu-S-generic-expression}.
2633
2634 @comment  node-name,  next,  previous,  up
2635 @node Toolbar, TAGS, Imenu, Miscellaneous
2636 @section Toolbar
2637
2638 The R and S editing modes have support for a toolbar.  This toolbar
2639 provides icons to act as shortcuts for starting new S/R processes, or
2640 for evaluating regions of your source buffers.  The toolbar should be
2641 present if your emacs can display images.  @xref{Customization}, for ways
2642 to change the toolbar.
2643
2644 @comment  node-name,  next,  previous,  up
2645 @node TAGS, Rdired, Toolbar, Miscellaneous
2646 @section TAGS
2647
2648 The Emacs tags facility can be used to navigate around your files
2649 containing definitions of S functions.  This facility is independent of
2650 ESS usage, but is written here since ESS users may wish to take
2651 advantage of TAGS facility.  Read more about emacs tags in an emacs
2652 manual.
2653
2654 Etags, the program that generates the TAGS file, does not yet know the
2655 syntax to recognise function definitions in S files.  Hence, you will
2656 need to provide a regexp that matches your function definitions.  Here
2657 is an example call (broken over two lines; type as one line) that should
2658 be appropriate.
2659
2660 @example
2661 etags --language=none
2662 --regex='/\([^ \t]+\)[ \t]*<-[ \t]*function/\1/' *.R
2663 @end example
2664
2665 This will find entries in your source file of the form:
2666
2667 @example
2668 some.name <- function
2669 @end example
2670
2671 with the function name starting in column 0.  Windows users may need to
2672 change the single quotes to double quotes.
2673
2674 @comment  node-name,  next,  previous,  up
2675 @node Rdired, , TAGS, Miscellaneous
2676 @section Rdired
2677
2678 Ess-rdired provides a dired-like buffer for viewing, editing and
2679 plotting objects in your current R session.  If you are used to using
2680 the dired (directory editor) facility in Emacs, this mode gives you
2681 similar functionality for R objects.
2682
2683 To get started, first make sure you can load ess-rdired.  Add the
2684 following to your .emacs and then restart emacs.
2685 @example
2686 (autoload 'ess-rdired "ess-rdired" 
2687   "View *R* objects in a dired-like buffer." t)
2688 @end example
2689
2690 Start an R session with @kbd{M-x R} and then store a few
2691 variables, such as:
2692
2693 @example
2694 s <- sin(seq(from=0, to=8*pi, length=100))
2695 x <- c(1, 4, 9)
2696 y <- rnorm(20)
2697 z <- TRUE
2698 @end example
2699
2700 Then use @kbd{M-x ess-rdired} to create a buffer listing the
2701 objects in your current environment and display it in a new window:
2702 @example
2703             mode length
2704   s      numeric    100
2705   x      numeric      3
2706   y      numeric     20
2707   z      logical      1
2708 @end example
2709
2710 Type @kbd{C-h m} or @kbd{?} to get a list of the keybindings for this
2711 mode.  For example, with your point on the line of a variable, `p' will
2712 plot the object, `v' will view it, and `d' will mark the object for
2713 deletion (`x' will actually perform the deletion).
2714
2715 @comment  node-name,  next,  previous,  up@chapter Using S4
2716 @node Mailing lists/bug reports, Customization, Miscellaneous, Top
2717 @chapter Bugs and Bug Reporting, Mailing Lists
2718
2719 @menu
2720 * Bugs::
2721 * Reporting Bugs::
2722 * Mailing Lists::
2723 @end menu
2724
2725 @node Bugs, Reporting Bugs, Mailing lists/bug reports, Mailing lists/bug reports
2726 @section Bugs
2727 @cindex bugs
2728 @include bugs.texi
2729
2730 @comment  node-name,  next,  previous,  up
2731 @node Reporting Bugs, Mailing Lists, Bugs, Mailing lists/bug reports
2732 @section Reporting Bugs
2733 @cindex Bug reports
2734 @pindex ess-submit-bug-report
2735 @include bugrept.texi
2736
2737 @comment  node-name,  next,  previous,  up
2738 @node Mailing Lists,  , Reporting Bugs, Mailing lists/bug reports
2739 @section Mailing Lists
2740
2741 @include mailing.texi
2742
2743 @c _not_yet_ @node Help OS, Installation, Help for Statistical Packages, Top
2744 @c _not_yet_ @comment  node-name,  next,  previous,  up
2745 @c _not_yet_ @chapter Help, arranged by Operating System
2746 @c _not_yet_
2747 @c _not_yet_ @menu
2748 @c _not_yet_ * Unix installation::
2749 @c _not_yet_ * Microsoft Windows installation::
2750 @c _not_yet_ * System dependent::            Other variables you may need to change
2751 @c _not_yet_ @end menu
2752
2753
2754
2755 @comment  node-name,  next,  previous,  up
2756 @node Customization, Key Index, Mailing lists/bug reports, Top
2757 @appendix Customizing ESS
2758 @cindex customization
2759
2760 ESS can be easily customized to your taste simply by including the
2761 appropriate lines in your @file{.emacs} file.  There are numerous
2762 variables which affect the behavior of ESS in certain situations which
2763 can be modified to your liking.  Keybindings may be set or changed to
2764 your preferences, and for per-buffer customizations hooks are also
2765 available.
2766
2767 Most of these variables can be viewed and set using the Custom facility
2768 within Emacs.  Type @kbd{M-x customize-group RET ess RET} to see all the
2769 ESS variables that can be customized.  Variables are grouped by subject
2770 to make it easy to find related variables.
2771
2772 @c Stephen deleted incomplete variable list Wed 25 Aug 2004.
2773
2774 @node Key Index, Concept Index, Customization, Top
2775 @unnumbered Key (Character) Index
2776 @printindex ky
2777
2778
2779 @c @node Command Index, Concept Index, Key Index, Top
2780 @c @unnumbered Command and Function Index
2781 @c @printindex fn
2782
2783
2784 @comment  node-name,  next,  previous,  up
2785 @node Concept Index, Variable and command index, Key Index, Top
2786 @unnumbered Concept Index
2787 @printindex cp
2788
2789 @node Variable and command index,  , Concept Index, Top
2790 @unnumbered Variable and command index
2791 @printindex vr
2792
2793 @contents
2794
2795 @bye
2796 @c Remember to delete these lines before creating the info file.
2797 @c Why?  I makeinfo all of the time without following this advice.
2798 @iftex
2799 @lucidbook
2800 @bindingoffset = 0.5in
2801 @parindent = 0pt
2802 @end iftex
2803
2804 @comment Local Variables:
2805 @comment TeX-master: "ess.texi"
2806 @comment End: