6
\setbeamercovered{transparent}
10
\usepackage[english]{babel}
11
\usepackage[latin1]{inputenc}
13
\usepackage[T1]{fontenc}
14
% Or whatever. Note that the encoding and the font should match. If T1
15
% does not look nice, try deleting the line with the fontenc.
18
\title[Emacs and R]{Emacs enhances data analysis and programming with R}
19
\subtitle{ESS useR Short Course}
20
\author[Rossini]{A.J.~Rossini}
22
\institute[Novartis Pharma AG]
24
Modeling and Simulation \\
30
{14.06.2006 / useR-2006}
33
% This is only inserted into the PDF information catalog. Can be left
36
% Delete this, if you do not want the table of contents to pop up at
37
% the beginning of each subsection:
38
% \AtBeginSubsection[]
40
% \begin{frame}<beamer>
41
% \frametitle{Outline}
42
% \tableofcontents[currentsection,currentsubsection]
53
\section{Introduction}
57
%% \tableofcontents[hideallsubsections]
59
\item Introduction (now, 15 minutes)
60
\item Using Emacs (45 minutes)
61
\item Using ESS (60 minutes)
63
\item Exercise 2: Sweave
64
\item Emacs extensions (30 minutes)
65
\item Emacs Lisp (30 minutes)
66
\item Discussion and Misc Topics (related Emacs tools, ESS extensions, future designs)
70
\subsection[Goals]{Goals for Today}
73
\frametitle{\#1: Efficient Program Editing}
74
\framesubtitle{Edit, and let the computer repeat}
76
\item Weird archaic keystrokes are dominant
77
\item Weird archaic keystrokes can make life easier
78
\item Menus and toolbars help Emacs
79
\item Knowing R and data analysis means we can enhance related activities.
80
\item Folding editors, Object explorers
85
\frametitle{\#2: Process Interaction}
86
\framesubtitle{You enter text for the process, so edit\ldots}
88
\item R vs. ``emacs -f R''
90
\item Approaches for interacting
91
\item Practical Directory layout
96
\frametitle{\#3: Emacs is Extended and Extensible}
97
\framesubtitle{Lisp and other hackers are your friends}
99
\item Introduction to Lisp and Emacs Lisp
100
\item Lisp extends Emacs
102
\item Future Extensions??
107
%% \frametitle{Make Titles Informative.}
108
%% You can create overlays\dots
110
%% \item using the \texttt{pause} command:
119
%% using overlay specifications:
127
%% using the general \texttt{uncover} command:
129
%% \uncover<5->{\item
131
%% \uncover<6->{\item
138
\frametitle{Disclaimer}
140
\item ESS (and Emacs) is many (different) things to different
142
\item Even for R development, the variation in personal philosophies
143
and approaches for use is extremely high (even in the Core
145
\item Religious issues focusing on Emacs should be discussed elsewhere
146
(c.f. \url{http://www.dina.kvl.dk/~abraham/religion/})
150
\begin{frame} \frametitle{Demo!}
151
\framesubtitle{It'll get boring before it gets better\ldots}
152
\alert{Please note or comment on any part that you'd like covered later.}
155
\subsection{Introducing Emacs}
157
\begin{frame} \frametitle{Overview}
159
\item Emacs is the extensible, customizable, self-documenting
160
real-time display editor.
161
\item One of the oldest and yet still most powerful display editors
162
\item The name \textbf{Emacs} comes from Editor (or Extensible)
163
MACroS. (source of other amusing acronym expansions)
164
\item Originally written in 1976 as a set of extensions to TECO
165
(Text Editor and COrrector). It has since evolved.
169
\begin{frame} \frametitle{Pros and Cons for Emacs}
171
\item \alert{Why use Emacs?} It is a powerful text editor which
172
can be extended to be a general interface to a computer (everything can be done within it).
173
\item It is highly portable (in its own way) across many platforms.
174
\item \alert{Why do not use it?} It has a different user interface,
175
which is understandable given its age (little change since 1985).
176
\item It does not follow ``modern'' keybindings.
177
\item People don't understand Lisp (otherwise, what they want to do
178
could be done in Emacs)
180
\centerline{\alert{some people are allergic to it}}
184
\frametitle{On-line Resources}
187
\item Emacs Wiki: \url{http://www.emacswiki.org/}
188
\item Emacs \url{http://www.gnu.org/software/emacs/}
189
\item XEmacs \url{http://www.xemacs.org/}
190
\item Emacs Lisp Library \url{http://www.damtp.cam.ac.uk/user/sje30/emacs/ell.html}
195
\frametitle{The Emacsen Problem}
196
\framesubtitle{different religions cause stress}
197
There are many variants or dialects of Emacs (\textit{similar to the
198
S language having AT\&T's S, Insightful's S-PLUS, and R-core's R})
200
\item Emacs: ``classic version''
201
\item XEmacs: ``experiments'' (GUIs, dynamic loading, packaging)
202
\item SXEmacs: ``splinter'' (Unix-focus, streamlining XEmacs)
205
ESS support is best in order (Emacs, XEmacs, SXEmacs). Most active
206
ESS developers use Emacs. Users seem to be split 50/50 between
208
No bug reports on SXEmacs\ldots
212
\frametitle{Installation}
213
\framesubtitle{the bane of Emacs}
214
Installation can be tricky:
216
\item Linux: Emacs usually can be installed or is preinstalled
217
\item Microsoft: XEmacs is easier to install, Emacs might be better
219
\item Mac OSX: Emacs, AquaEmacs; via Fink, or UCLA package, or\ldots
222
We aren't dealing with this here!
225
\begin{frame} \frametitle{Editing methodology}
226
\framesubtitle{Emacs resembles modern editors unlike dual-mode VI}
229
\item Idea: every keystroke (or sequence of keystrokes) generates a
230
list to evaluate (i.e. command, or lisp function with arguments).
231
\item Pressing ``X'' evaluates the list (self-insert-command "X") (we'll talk about Lisp later)
232
\item Modifiers extend the keyboard (CTL, SHIFT, ALT, pressed
233
simultaneously, some such as ESC, META, and others are pressed
234
first, released, and then followed by a key).
238
\subsection{Introducing ESS}
241
\frametitle{Overview}
242
\framesubtitle{ESS augments Emacs for R}
244
\item Emacs Speaks Statistics (or Emacs Statistical System)
245
\item Oldest active statistically-focused OSS project (1989).
246
\item Design goal: a consistent interface unifying batch and
247
interactive data analysis styles.
248
\item Novelty (at the time): process control, unified interface.
249
\item String (stream) operations; ``cheap parser''.
250
\item Supports R, S-PLUS, SAS, Stata, LispStat
251
\item Current development team (n=6) spans the US and Europe.
255
\begin{frame} \frametitle{History}
257
\item 3 branches: S-mode, SAS-mode, Stata-mode
258
\item S-mode: 1989, 2 groups managing the project before (Bates/F
259
Ritter/E Kademan, M Meyer, DM Smith (now Insightful)).
260
R added in 1995 (Rossini/Maechler)
261
\item SAS: '94, Tom Cook ('92, John Sall, SAS). Integrated '95-6, Rossini
262
\item Stata-mode: 1997, Thomas Lumley. Added 1997 (Rossini).
263
\item 1997: last major restructuring (``grand unification'')
264
\item 2004: switch leaders: Maechler takes over
266
\alert{We are still suffering from the 1997 grand unification.}
270
\frametitle{Interactive Programming}
271
\framesubtitle{Everything goes back to being Lisp}
273
\item Interactive programming (as originating with Lisp): works
274
extremely well for data analysis (Lisp being the original
275
``programming with data'' language).
276
\item Theories/methods for how to do this are reflected in styles
279
\alert{Good Statistical Analysis is on-line Interactive Programming}
283
\frametitle{Installation}
284
\framesubtitle{We have to deal with this here, though\ldots}
286
\item Fetch the ESS package (tar or zip-file)
288
\item add a line in \textbf{.emacs} to load the \textbf{ess-site.el} file.
289
\item restart Emacs (or \textbf{M-x load-file /path/to/ess-site.el}).
294
\frametitle{Review: Introduction}
296
\item ESS is a program in Lisp to extend Emacs
297
\item Characteristics: OSS, developed initially to make life easier;
298
continued development supported research in enhanced data analysis
300
\item Emacs has strengths and weaknesses; these are usually
301
different than percieved strengths and weaknesses.
305
\section{Using Emacs}
307
\subsection{Overview: Emacs}
309
\begin{frame} \frametitle{Goals}
311
\item use of Emacs to edit files
312
\item filesystem interaction
316
\subsection{Getting Started}
318
\begin{frame}[fragile]
319
\frametitle{Starting (X)Emacs}
320
\framesubtitle{trivial but essential}
321
\alert{emacs} can be used instead of \alert{xemacs}.
323
xemacs <filename> run xemacs, edit <filename>
324
xemacs -nw run xemacs in _text_ mode
325
(nw="No Window"; useful for
326
slow remote connections)
329
\item Once started, no need for more.
330
\item \alert{Only run one Emacs session}. This is a cardinal rule,
332
(c.f.\hyperlink{keystrokes:fileloading}{\beamerbutton{file-loading section}})
337
\begin{frame}[fragile]
338
\frametitle{Breaking and Quitting!}
339
\framesubtitle{essential knowledge}
342
\item Decide you were wrong while Emacs works: \verb+C-g+ (universal break)
343
\item Quit and terminate: \verb+C-x C-c+ (will usually prompt you
344
for any files which are modified but not saved)
349
\begin{frame}[fragile]
350
\frametitle{Understanding Keystrokes.}
352
\item \verb+[tab]+ is the TAB (indent) key.
353
\item \verb+[return]+ is the Return (carriage return, enter) key.
354
\item \textbf{C-h} means press \alert{control key} AND ``\alert{h}'' key at same time.
355
\item \textbf{ESC-h} means press \alert{ESC key} THEN ``\alert{h}''
356
\item \textbf{M-h} means press \alert{ALT key} AND ``\alert{h}''
357
\item \textbf{M-C-h} means press Meta or Alt while pressing h. OR
358
(if no meta/alt): ESC THEN (control and h keys together).
360
Older keyboards (and sometimes older Macs) without ALT or Meta lead
361
to confusion between ESC and Meta, but ideally they should be different.
364
\begin{frame} \frametitle{Stopping Activity}
365
\framesubtitle{you need to know this\ldots}
366
\alert{C-g} stops the current Emacs activity to the best of its ability.
370
\frametitle{Windows and Frames}
372
\item Window: a different view on (usually) a different buffer within the same application
373
\item Frame: a different window/application in the windowing system.
377
\begin{frame}[fragile]
378
\frametitle{File suffices drive mode setup}
379
\framesubtitle{Use the right file name formats:}
381
\item \verb+.S+, such as \verb+critical_simulation.S+
382
\item \verb+.R+, such as \verb+speedy_simulation.R+
384
There are other ways to force a file to be edited in a particular
385
mode, but at this point, keep it simple.
389
\frametitle{Commands}
391
Emacs has a single command-entry mode. There are 2 approaches for commands:
393
\item \textbf{M-x (command-name)}
394
\item keystrokes/toolbars/menus (which implement the above)
399
\subsection{Keystrokes}
402
\frametitle{Learning the Strokes.}
404
\item forced practice: painful but fast. Keep a copy of the
405
reference cards nearby! (usually 2-3 days of severe pain,
407
\item accelerators and menus can help: but they quickly become a crutch.
408
\item Consider working through the tutorial (\textbf{C-h t}).
410
\alert{this is a major issue for speed typists converting to/from
414
\begin{frame}[fragile]
415
\frametitle{Loading Files}
416
\label{keystrokes:fileloading}
418
\item \verb+C-x C-f+ (load new file, \textbf{not} deleting old)
419
\item \verb+C-x 4 C-f+ (load new file in different window)
420
\item \verb+C-x 5 C-f+ (load new file in different frame)
422
(c.f. \hyperlink{emacs:basics}{\beamerbutton{basics}})
425
\begin{frame}[fragile]
426
\frametitle{Changing Active Buffer (edit file)}
427
To edit (operate on) another file:
429
\item \verb+C-x b+ (switch to new buffer in same window)
430
\item \verb+C-x 4 b+ (replaces current file in different window)
431
\item \verb+C-x 5 b+ (replaces current file in different frame)
433
Buffers represent the files you are editing (explain).
437
\frametitle{Review of Common Keystrokes}
438
\framesubtitle{Demo and pain}
442
\subsection{In Any Emacs Buffer}
444
\begin{frame}[fragile] \frametitle{Moving Around}
446
C-v Move forward one screenful
447
M-v Move backward one screenful
448
C-l Clear and redraw screen
449
M- -> Meta-<right> - moves forward a word
450
M- <- Meta-<left> - moves back a word
451
M- |^ Meta-<up> - move up a paragraph
452
M- V Meta-<down> - move down a paragraph
453
M- < Meta-<less than> - move to file start
454
M- > Meta-<greater than> - move to file end
458
\begin{frame}[fragile] \frametitle{Cut and Paste}
461
C-k _K_ill from the cursor position to
463
C-y Recover/Paste (_Y_ank) killed text
465
M-y recover former killed text (after C-y).
466
Repeat to go back through stack).
472
\begin{frame}[fragile] \frametitle{Loading / Saving Files}
474
C-x C-f _F_ind a file
475
C-x C-s _S_ave the file
477
If you find a second file with C-x C-f,
478
the first file remains inside Emacs.
479
You can switch back to it by finding it
480
again with C-x C-b. This way you can get
481
quite a number of files inside Emacs.
486
\begin{frame}[fragile] \frametitle{Managing Buffers and Windows}
488
C-x 0 Move between windows
491
(i.e., kill all other windows).
492
C-x b Switch to new _b_uffer
493
C-x C-b List _b_uffers
498
\begin{frame}[fragile] \frametitle{Search and Replace}
500
M-x (then) replace-string
502
M-x (then) query-replace-string
503
Will ask you, for each match,
504
if you really want to replace
505
the old string with the new one.
506
C-s _S_earch forward (repeat to
507
reuse past search strings)
508
C-r Search _R_everse (repeat to
509
reuse past search strings)
514
\begin{frame}[fragile] \frametitle{Misc Emacs Actions}
517
C-h c (command) _H_elp on this _c_ommand
519
C-u 8 (character or command)
520
Repeat character/command 8 times
523
C-x C-c Stop and exit (_c_lose) Emacs
529
\frametitle{Point and Mark}
530
\framesubtitle{critical concepts to learn}
533
\item Point: where the cursor is.
534
\item Mark: a location that you've decided (actively or inactively)
536
\item Example: Move cursor somewhere. \textbf{M-x set-mark} or
538
\item Exchange point and mark: \textbf{M-x
539
exchange-point-and-mark} or \textbf{C-x C-x}.
543
\subsection{Review: Using Emacs}
547
\framesubtitle{Emacs}
549
\item \textbf{C-g} stops emacs activity and returns to edit mode; \textbf{C-x C-c} quits
550
\item Try to use the keyboard and not the mouse, menus, or toolbars.
551
\item Keypresses are simply commands.
552
\item Biggest user headache? Differenting commands and text entry
553
\item Buffers represent the files you are editing. Morally, they
554
are the files themselves (with important exceptions).
561
\subsection{Overview: ESS}
564
\frametitle{Overview: ESS}
565
This section should provide an overview for
568
\item interaction with R
569
\item facilitating help
570
\item reusing transcripts
573
and finally, \alert{putting it all together}
578
\begin{frame}[fragile]
579
\frametitle{Coding Style}
580
\framesubtitle{Indentation makes code readable}
584
\item \verb+#+ gets moved to the right-side of the line
585
\item \verb+##+ is placed at the current indentation level
586
\item \verb+###+ is placed flush-left.
590
\begin{frame}[fragile]
591
\frametitle{Indentation Example}
595
## but this is at level
601
\begin{frame}[fragile]
602
\frametitle{Editing, ESS adds\ldots}
604
\item Automatic fontification, indentation
606
If R is running in another buffer:
608
\item evaluation of lines (C-c C-n), regions (C-c C-r), functions
609
(C-c C-f), and buffers (C-c C-b)
610
\item help output in other buffers (and via command, C-c C-v)
611
\item Object (data, function) completion
613
\item \verb+C-c [tab]+
614
\item \verb+[tab]+ (sometimes).
616
\item Filename completion: M-\[tab\]
620
\begin{frame}[fragile]
621
\frametitle{R editing buffer}
622
\framesubtitle{Usually named for the file being edited}
623
(mode line says "ESS[S]")
625
C-c C-j Send line to R
626
C-c C-n Send line to R
627
and go to _n_ext line
628
C-c C-r Send highlighted _r_egion to R
629
C-c C-b Send whole _b_uffer to R
630
C-c C-f Send _f_unction surrounding
632
C-c C-v xxx get R help on "xxx"
636
\subsection{Interactive}
642
\item At the command line
646
\begin{frame}[fragile]
647
\frametitle{R process within Emacs (on start)}
648
\framesubtitle{starting from the command line or launcher}
649
Replace the command \textbf{R} with one of:
651
emacs -f R run (x)emacs, starting R
654
adds a few nice features to the command interface. (follow with
655
\textbf{\&} to background the process; \verb+xemacs+ might also
659
\begin{frame}[fragile]
660
\frametitle{R process within Emacs (running emacs)}
661
\framesubtitle{Starting from a running emacs}
663
M-x R Start R process buffer
664
M-x R-mode Change mode of current buffer
669
\begin{frame}[fragile]
670
\frametitle{Evaluate file contents}
671
\framesubtitle{working from the editing (ESS) buffer}.
673
From a file of commands:
675
\item Send current line to R: \verb+C-c C-j+
676
\item Send current function to R (assumes the cursor is in the
677
function body): \verb+C-c C-f+.
678
\item Send current region (highlighted) to R \verb+C-c C-r+
679
\item Send whole buffer/file to R \verb+C-c C-b+
683
\begin{frame}[fragile]
684
\frametitle{Object and File completion}
685
Completion of objects (functions and data):
687
\item \verb+C-c [tab]+
688
\item \verb+[tab]+ (sometimes).
693
\frametitle{Dumping Objects}
694
\framesubtitle{Getting objects back}
695
(for modification, saving, eventual reloading):
697
\item \textbf{C-c C-d} dumps the named object into an editing buffer
698
\item Examples: today's date for use as a log file; (140606), ``lm''.
699
\item if object doesn't exist: create a blank buffer
700
\item if object exists: insert the object's textual representation (no comments)
701
\item The file will be stored in \textbf{/tmp/username.objectname.R}
702
(unless you want it elsewhere or named something else).
704
Type commands into the edit file, evaluate them when desired, edit
705
as needed for correctness (and comment mistakes, with reasons for
706
them, for later reminders and documentation).
709
\begin{frame}[fragile]
710
\frametitle{Commandline History}
711
\framesubtitle{ESS remembers what you've done}
712
Search command-line history ``manually'', matching on current input
714
\item backwards: \verb+M-p+
715
\item forwards: \verb+M-n+
717
Complete current line based on command-line history:
719
\item backwards: \verb+\C-[uparrow]-p+
720
\item forwards: \verb+M-n+
722
If you are reviewing old commands, to re-enter it (i.e. cursor on that line)
727
\frametitle{Philosophy: Files are ``truth''}
728
\framesubtitle{Don't believe your .RData}
730
\item This is a generally decent approach.
731
\item Saving objects in binary format in special files can be a
733
\item Work from an R file, \emph{submitting} commands to the R
734
process. This saves the source, and allows for structuring of the
735
input, along with having a transcript of the order of commands to
736
understand reproducibility aspects.
740
\begin{frame}[fragile]
741
\frametitle{Working from R process}
742
\framesubtitle{from the process (inferior ESS, or iESS) buffer}
743
\alert{not usually recommended}
745
\item One improvement is to use a \verb+source()+-like facility. To
746
source a file into R (within ESS): \textbf{C-c C-l} (load file)
747
\item To find what the errors are (if any): \textbf{C-c `} (backquote).
749
The latter will tell you what the error is. You'll have to go back
750
to the file (\textbf{C-x C-b} or use \textit{Buffers} menu item to
751
bring in back to the screen) and correct it.
754
\begin{frame}[fragile]
755
\frametitle{Working from R buffer}
756
\framesubtitle{from the editing (ESS) buffer}
757
Better yet, use a file, and send material from the file straight to
758
the process. This works if the file ends in the proper suffix (and
759
hence, the mode at the bottom should say ``ESS''). The following is
762
\item Send current line to R: \textbf{C-c C-j}
763
\item Send current function to R (assumes the cursor is in the
764
function body): \textbf{C-c C-f}
765
\item Send current region (highlighted) to R: \textbf{C-c C-r}
766
\item Send whole buffer/file to R: \textbf{C-c C-b}
771
\frametitle{Philosophy: RData is true}
772
\framesubtitle{Editing objects without source}
774
\item This is a dangerous approach; corruption of the RData file is
775
more difficult to fix using an editor or other external tools than
776
corruption of text files, usually.
777
\item Trusting .RData to have what you've done is rather suboptimal
778
strategy (quite prone to user mistakes)
783
\frametitle{If you must use a command line\ldots}
785
\item This style is useful for quick and dirty exercises/testing.
786
\item Transcripts can be cleaned and edited to record the salient
787
points of the sesssion.
791
\subsection{Putting it together}
794
\frametitle{Begin ESS/Emacs/R}
796
\item Start XEmacs (in a terminal window, enter \textbf{xemacs \&})
797
\item Start R (\textbf{M-x R}).
798
\item Load a file (\textbf{C-x C-f} \textit{filename})
802
\begin{frame}[fragile]
803
\frametitle{Data Analysis Example}
807
\begin{frame}[fragile] \frametitle{Function Editing}
809
\item demo.R: evaluate.
810
\item Try editing existing functions: \textbf{my.test.function} and
811
\textbf{that}, by \textbf{C-c C-d this}. Remember that you should
812
be able to complete the name using \textit{ajr.t}\textbf{SPACE}
813
(i.e. Control-C, then SPACE key). Generally, completion of
814
variables and functions can be done using \textbf{C-c [tab]} in the
815
editing buffer, and \textbf{SPACE} in the command entry area (at
816
the very bottom of the Emacs screen/window).
820
\subsection{Special Facilities and Activties}
823
\frametitle{Navigating Help Buffers}
825
\item To get help on a function (help(``lm'')) without
826
spoiling your input line: \textbf{C-c C-v}
827
\item Navigation of sections: ``n'' next section, ``p'' prev section.
828
\item evaluation of example: ``l'' (eval line) ``r'' eval region.
829
\item searching: ``/'' isearch forward
830
\item kill-buffer and go \textit{back}: ``x''
836
\frametitle{Using Transcripts}
837
\framesubtitle{for teaching, reproduction, and audits}
839
\item Transcript suffix: .Rt
840
\item Stepping through entries:
841
\item Cleaning transcripts: \textbf{M-x ess-transcript-clean-buffer}
842
\item Cleaning transcripts: \textbf{M-x ess-transcript-DO-clean-region} (even when read-only toggled)
847
\frametitle{Using Multiple Processes}
848
\framesubtitle{For when you want to multitask}
849
ESS supports multiple processes. This is useful for
851
\item testing on multiple versions of R
852
\item testing on R and S-PLUS (and S4, if one still has a copy)
853
\item inefficient multiprocessing
858
\frametitle{Using Remote Processes}
859
\framesubtitle{loading other people's computers}
860
Since we are capturing/using R text I/O, local or remote is not an
861
issue (running R in an Emacs shell, logged in (shell account via
862
telnet, ssh, rlogin) to another machine)
864
\item \textbf{M-x ESS-remote}
865
\item follow instructions
869
\begin{frame}[fragile]
870
\frametitle{Customizing ESS}
871
See (commented out) example customizations in ess-site.el (assuming
872
that the lisp files are installed:
874
M-x locate-library [return] ess-site [return]
878
M-x customize-group [return] ess
880
helps to review possible customizations (this is an alternative to
881
editing the \textbf{\~{}/.emacs} file for setting customizing
885
\subsection{Sweave Support}
888
\frametitle{Overview: Sweave}
889
Sweave originated from the Literate Data Analysis philosophy which
890
in itself was the idea of applying Literate Programming to the
891
specialized programming discipline \emph{interactive data analysis}.
893
Support for editing Noweb files existed within ESS 4 years before
894
Sweave, but Sweave is a ``Killer App''.
898
\frametitle{Documents as Programs}
900
\item Every electronic document is a ``computer program'' (sometimes
901
at a primitive level) for some rendering device or program (such
902
as: Microsoft Word; Postscript printers; Adobe Acrobat Reader;
904
\item This is the general theory behind the WWW, as well as the
905
so-called \emph{Semantic Web}.
910
\frametitle{Literate Programming}
911
A programming methodology devised by Donald Knuth in the late 70s,
912
early 80s, which mixes computer programs doing mathematics with
913
mathematical documentation (formulas, theorems, algorithms).
917
\item Tangling: translating document into undocumented computer source code for
919
\item Weaving: translating document into documentation for the source code.
921
The original tool was called Web (predates the \textit{World-Wide-Web}).
924
\begin{frame} \frametitle{Literate Statistical Practice}
925
\framesubtitle{or \emph{Literate Data Analysis:}}
926
The application of literate programming to statistics; recognizing
927
that statistical data analysis is a specialized programming activity
928
with different characteristics than systems programming or
929
applications programming.
931
(realization prototype: ESS-Noweb and Sweave).
934
\begin{frame} \frametitle{ESS enhances Sweave}
936
\item context specific modes (doc: latex, html, muse; code: R, etc).
937
\item chunk and thread evaluation.
938
\item functions for processing Sweave files.
943
\frametitle{Evaluation}
944
\framesubtitle{Chunks and Threads}
946
\item eval-chunk (run code inside a code chunk)
947
\item eval-thread (run code inside a series of code chunks)
952
\frametitle{Accelerated Sweave Development }
954
\item ESS has specialized support
955
\item use Makefiles (editor-neutral approach)
956
\item \textbf{M-x ess-makeSweave} or \textbf{M-n s}
957
\item \textbf{M-x ess-makeLatex} or \textbf{M-n l}
958
\item \textbf{M-x ess-makePS} or \textbf{M-n p}
959
\item \textbf{M-x ess-makePDF} or \textbf{M-n P}
960
\item \textbf{M-x ess-insert-Sexpr} or \textbf{M-n x}
964
\subsection{Review: ESS}
967
\frametitle{Review: Using ESS}
969
\item ESS for R has 4 modes: editing, interactive, transcript, help.
970
\item Focus on learning to use keystrokes rather than mouse.
974
\section{Emacs is Extended}
977
\frametitle{Packages and Extensions.}
978
Emacs has many modes:
980
\item language-specific markup (programming, markup)
981
\item editor behavior (spell checking, pending delete, folding,
982
editor emulation (vi, brief))
983
\item IDE capabilities (object explorers, completers)
985
\item communication (mail, news, www, rdf)
986
\item sub (inferior) process control (telnet, R, \ldots)
987
\item publication (text mode conversion)
988
\item version control interfaces
989
\item anything you can program!
994
\frametitle{Relevant to Data analysis and R}
996
\item folding modes (outline; however, the newer version, allout,
998
\item object explorers (ecb)
999
\item documentation modes
1001
\item specialized: latex, html, rtf
1002
\item generic: muse, \ldots (idea: simple markup which translates to
1003
html, latex, texinfo, etc).
1010
A directory/file explorer and navigator.
1014
\frametitle{Emacs Code Browser}
1016
\item ESS integrates to support R
1017
\item Extension/customization: through imenu support.
1018
\item file-level navigation and objects, editing history of files,
1019
files in current directory, directory tree.
1021
(demo with R-examples/FCS.R)
1026
\framesubtitle{a mode for documentation and notes}
1028
\item Wiki-like editing, hyperlinks, within text.
1030
\item Supports generation of latex, pdf, (x)html, xml.
1035
\frametitle{Planner: Task management}
1036
\framesubtitle{getting organized and tracking activity}
1038
\item Plain-text task management and organization
1039
\item Supports many common time-management approaches (GTD, ).
1040
\item Extremely customizeable
1044
\subsection{LaTeX Extensions}
1047
\frametitle{LaTeX Support}
1048
\framesubtitle{nearly WYSIWYG}
1050
\item AUC-TeX: latex document support
1051
\item BiBTeX-mode and RefTeX: citation management
1052
\item X-Symbol: native display of mathematical symbols
1053
\item tex-preview: You can see what you will get (YCSWYWG)
1057
\section{Lisp and Emacs Lisp}
1060
\frametitle{Customizing Emacs}
1061
\framesubtitle{Sometimes with Lisp}
1063
\item Critical components for customizing Emacs: current best
1064
practices suggest that you customize via ``M-x customize''. (this
1065
is a recent (last 5 years) change!).
1066
\item However, adding Lisp commands to your \textbf{.emacs} file is
1067
still very useful (and sometimes required).
1068
\item Note that commas denote comments (from the comma until the end
1073
\subsection{Introduction to Lisp}
1075
\begin{frame}[fragile]
1077
Lisp (LISt Processor) is different than most high-level computing
1078
languages, and similar to Emacs, it is very old (1956). Lisp is
1079
built on lists of things which might be evaluated:
1081
(function data1 data2 data3)
1085
'(function data1 data2 data3)
1087
The difference is important -- lists of data (the second) are not
1088
functions applied to data (the first).
1091
\begin{frame}[fragile]
1092
\frametitle{Evaluation}
1093
Lisp is built on lists of things which might be evaluated:
1095
(function data1 data2 data3)
1099
'(function data1 data2 data3)
1100
(list function data1 data2 data3)
1102
The difference is important -- lists of data (the second) are not
1103
functions applied to data (the first).
1106
\begin{frame}[fragile]
1107
\frametitle{Defining Variables}
1108
\framesubtitle{Setting variables}
1110
(setq <variable> <value>)
1114
(setq ess-source-directory
1115
"/home/rossini/R-src")
1119
\begin{frame}[fragile]
1120
\frametitle{Defining on the fly}
1122
(setq ess-source-directory
1123
(lambda () (file-name-as-directory
1125
(concat (default-directory)
1126
ess-suffix "-src")))))
1128
(Lambda-expressions are anonymous functions, i.e. ``instant-functions'')
1132
\begin{frame}[fragile]
1133
\frametitle{Function Reuse}
1134
By naming the function, we could make the previous example reusable
1137
(defun my-src-directory ()
1138
(file-name-as-directory
1140
(concat (default-directory)
1141
ess-suffix "-src"))))
1145
(setq ess-source-directory (my-src-directory))
1149
\begin{frame}[fragile]
1150
\frametitle{Programming Emacs Lisp}
1152
There are three general approaches to testing, evaluating, and
1153
deploying Emacs Lisp code.
1155
\item Loading files: \verb+M-x load-file <filename.el>+
1156
\item Using the \verb+*scratch*+ buffer
1157
\item \verb+ielm+ , an emacs-lisp REPL
1159
Review the latter two
1162
\begin{frame}[fragile]
1163
\frametitle{Playing in the scratch buffer.}
1165
\item \verb+C-x b *scratch*+
1166
\item (display-time)\verb+C-j+
1167
\item (setq my-test ``asdf'')\verb+C-j+
1168
\item my-test\verb+C-j+
1173
\frametitle{ielm: command-line usage.}
1176
\item follow the instructions for more information (similar to using
1177
R in interactive mode)
1181
\subsection{Extending Emacs and ESS}
1184
\frametitle{Organization.}
1185
\framesubtitle{Structure of ESS}
1188
\item Reading the code
1189
\item making extensions
1194
\frametitle{Debugging.}
1196
\item Set options to ``debug on error'' and ``debug on signal''.
1197
Both bring up the stack-trace of the current status of the lisp
1198
program (nesting and variable values).
1199
\item Look for errors in loading to determine the path taken to the error
1200
\item more sophisticated debuggers exist.
1206
\frametitle{Idea generation: SLIME}
1207
\framesubtitle{Lisp IDE suggests ESS improvements}
1209
\item Use R subprocesses (old idea of DTL).
1210
\item Synchronize processes
1215
\section{Discussion}
1218
\frametitle{Future?}
1220
\item Continued support for R within ESS
1221
\item Object and formating support
1227
\frametitle<presentation>{Summary}
1229
% Keep the summary *very short*.
1232
Emacs takes time to learn, but rewards the user.
1236
Lisp is worth learning.
1239
% The following outlook is optional.
1240
\vskip0pt plus.5fill
1246
ESS is the oldest open-source statistics project; yet it can
1249
Many possible extensions for supporting work modes for
1250
Statisticians and Data Analysts. More need implementation.