ESS tutorial -- UseR! 2012

Richard M Heiberger

Martin Mächler

June 12, 2012

List of useful Web resources ("Links")

Files, R scripts, etc - directly for the tutorial (partly uploaded "real time")

% Created 2012-06-09 Sat 18:22
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{soul}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\AtBeginSection{\begin{frame} \frametitle{Outline} \tableofcontents[currentsection] \end{frame}}
\setbeamersize{text margin left=0.25cm}
\setbeamersize{text margin right=0.25cm}
\setbeamertemplate{navigation symbols}{}
\providecommand{\alert}[1]{\textbf{#1}}

\title{ESS tutorial, UseR! 2012 meeting}
\author{Stephen Eglen (UseR! 2011) -- \emph{small changes by Martin Mächler}}
\date{June 12, 2012 --- Handouts: 2012-06-09}
\hypersetup{
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs Org-mode version 7.8.11}}

\begin{document}

\maketitle

\section{Overview}
\label{sec-1}
\begin{frame}
\frametitle{Aims of the tutorial}
\label{sec-1-1}


\begin{itemize}
\item Introduce Emacs and ESS
\item Reproducible research: Sweave and Org-babel
\item Q \& A / Discuss future development
\item I'd like this to be very interactive. Feel free to ask
questions/comment.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Course material}
\label{sec-1-2}


\begin{itemize}
\item All available via \href{http://www.damtp.cam.ac.uk/user/sje30/ess11}{http://www.damtp.cam.ac.uk/user/sje30/ess11}
\item ess11.zip has the relevant material for today.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Disclaimers}
\label{sec-1-3}


\begin{itemize}
\item Learning Emacs takes a long time.
\item I'm a core-developer on Emacs and ESS.
\item I do not speak for emacs-devel or ess-core.
\item ESS has several statistical interfaces; only R will be discussed today.
\item Emacs (not XEmacs and SXEmacs) preferred.
\item I have limited knowledge of Windows.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{These slides}
\label{sec-1-4}


\begin{itemize}
\item Although there are pdf slides, probably most of the time I'll be
showing you emacs.
\item Of course, we could just view these slides in Emacs!
(View \texttt{ess-slides.pdf} in Emacs\ldots{})
\item These slides are written in Org mode/Beamer. To compile them
yourself (e.g., via \texttt{make}), you will need (e.g. in \href{file://.//~/.emacs}{file://\~/.emacs})
\end{itemize}

\begin{verbatim}
(setq org-beamer-frame-level 2)
\end{verbatim}
\end{frame}
\begin{frame}
\frametitle{Acknowledgements}
\label{sec-1-5}


\begin{itemize}
\item ESS-core, in particular Tony Rossini, who gave an 2006 tutorial,
from which these notes are based
\item ESS-help contributors
\item Org mode team, esp. Carsten Dominik, Eric Schulte and Dan Davison
\end{itemize}
\end{frame}
\section{Part I: Emacs}
\label{sec-2}
\begin{frame}
\frametitle{Why Emacs?}
\label{sec-2-1}


\begin{itemize}
\item Being productive with Emacs (Phil Sung).
\href{http://web.psung.name/emacs/}{http://web.psung.name/emacs/}

\href{http://www.gnu.org/software/emacs/tour}{http://www.gnu.org/software/emacs/tour}
\item Explore the guided tour file:
\includegraphics[width=.9\linewidth]{./resources/Emacs-guided-tour-1.pdf}
\item Older PDF from
\href{http://commons.wikimedia.org/wiki/File:Emacs-guided-tour-1.pdf}{http://commons.wikimedia.org/wiki/File:Emacs-guided-tour-1.pdf}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{History of Emacs}
\label{sec-2-2}


\begin{itemize}
\item Key architect: Richard Stallman.
\item Evolution from terminal only to rich graphical interface with remote
editing support.
\item Emacs release cycle is slow
\item XEmacs: 1990s gained prominence as alternative, more
graphical-friendly. (Less supported by ESS)
\item Emacs 23 very stable.
\item Emacs 24 due out next year? (<< written in 2011)
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Keystrokes, keybindings and functions}
\label{sec-2-3}


\begin{itemize}
\item Each keystroke is bound to a lisp function, even simple characters
like ``a''.
\item \texttt{C-h k a}
\item \texttt{C-h k C-a}
\end{itemize}

These create new \emph{buffers} which are shown in new windows.

\begin{itemize}
\item \texttt{M-x} is bound to execute-extended-command, which allows you to run a
command by name (there are many commands that are not bound to
keys).
\item Mapping between keybindings and commands is flexible; can change on
fly e.g.
\end{itemize}

\begin{verbatim}
(global-set-key "\C-ca" 'org-agenda)
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Understanding keystrokes}
\label{sec-2-4}


\begin{itemize}
\item \texttt{TAB} is the TAB (indent) key.
\item \texttt{RET} is the Return (carriage return, enter) key.
\item \texttt{C-h} means press control key AND ``h'' together
\item \texttt{ESC-h} means press ESC key THEN ``h''
\item \texttt{M-h} means press ALT or Meta key AND ``h'' together.
\item \texttt{M-C-h} means press Meta or Alt while pressing h and control key. OR
(if no meta/alt): ESC THEN (control and h keys together).
\item Older keyboards (and sometimes older Macs) without ALT or Meta
lead to confusion between ESC and Meta, but ideally they should
be different.
\end{itemize}

\begin{verbatim}
;; change CMD modifier to meta key (usually super).
(setq mac-command-modifier 'meta)
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Example keybinding that makes a key `smart'}
\label{sec-2-5}



\begin{verbatim}
;; From Peter.Weiss@Informatik.Uni-Oldenburg.DE (Peter Weiss)
;; Sun Nov 12 1995
(defun match-paren (arg)
"Go to the matching parenthesis if on parenthesis
otherwise insert %."
(interactive "p")
(cond ((looking-at "\\s\(")
(forward-list 1) (backward-char 1))
((looking-at "\\s\)")
(forward-char 1) (backward-list 1))
(t
(self-insert-command (or arg 1)))))

(global-set-key "%" 'match-paren)
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Moving Around}
\label{sec-2-6}



\begin{verbatim}
C-v Move forward one screenful
M-v Move backward one screenful
C-l Clear and redraw screen
M- -> Meta-<right> - moves forward a word
M- <- Meta-<left> - moves back a word
M- |^ Meta-<up> - move up a paragraph
M- V Meta-<down> - move down a paragraph
M- < Meta-<less than> - move to file start
M- > Meta-<greater than> - move to file end
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Cut and Paste}
\label{sec-2-7}


\begin{verbatim}
C-d _D_elete
C-k _K_ill from the cursor position to
end of line
C-y Recover/Paste (_Y_ank) killed text
(repeat to copy)
M-y recover former killed text (after C-y).
Repeat to go back through stack).
C-x u _U_ndo (multiple undo/redo)
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Loading / Saving Files}
\label{sec-2-8}


\begin{verbatim}
C-x C-f _F_ind a file
C-x C-s _S_ave the file

If you find a second file with C-x C-f,
the first file remains inside Emacs.
You can switch back to it by finding it
again with C-x C-b. This way you can get
quite a number of files inside Emacs.
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Managing Buffers and Windows}
\label{sec-2-9}



\begin{verbatim}
C-x 0 Move between windows
(Oh, not Zero!)
C-x 1 One window
(i.e., kill all other windows).
C-x b Switch to new _b_uffer
C-x C-b List _b_uffers
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Search and Replace}
\label{sec-2-10}


\begin{verbatim}
M-x (then) replace-string
Replace string
M-x (then) query-replace-string
Will ask you, for each match,
if you really want to replace
the old string with the new one.
C-s _S_earch forward (repeat to
reuse past search strings)
C-r Search _R_everse (repeat to
reuse past search strings)
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Misc Emacs Actions}
\label{sec-2-11}


\begin{verbatim}
C-h or C-h ? _H_elp
C-h c (command) _H_elp on this _c_ommand

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

C-g Stop, unhang.
C-x C-c Stop and exit (_c_lose) Emacs
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Evaluating lisp}
\label{sec-2-12}


Sometimes you will see me evaluate lisp code within emacs, rather than
typing a command. These are equivalent:

\begin{verbatim}
M-x next-line
(next-line)
above line eval'd using C-x C-e
\end{verbatim}
\end{frame}
\begin{frame}
\frametitle{Repeating yourself}
\label{sec-2-13}


Repeat C-n ten times:

C-u 10 C-n

C-u 70 \#

Can anyone guess what the following will do?

C-u C-n

C-u C-u C-n

Keyboard macros allow for arbritary key sequences to be repeated\ldots{}
\end{frame}
\begin{frame}[fragile]
\frametitle{Keyboard macros}
\label{sec-2-14}


\texttt{C-x (} lots of stuff \texttt{C-x )}


Can include counters. e.g.
\begin{verbatim}
C-x ( TAB step C-x C-k C-i RET C-x )
\end{verbatim}

will make:

\begin{verbatim}
step 0
step 1
step 2
\end{verbatim}
\ldots{}


(info ``(emacs)Keyboard Macros'')
\end{frame}
\begin{frame}
\frametitle{Point, mark and region}
\label{sec-2-15}


\begin{itemize}
\item \emph{point} is current location of cursor
\item \emph{mark} \texttt{C-SPC} to define another point
\item \emph{region} is text between mark and point
\item \texttt{C-x C-x} will swap point and mark.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Buffers}
\label{sec-2-16}


\begin{itemize}
\item Can contain:
\begin{enumerate}
\item contents of files, e.g. ess-slides.org
\item output from commands, e.g. \texttt{M-x man RET pwd RET}
\item \emph{inferior processes} e.g. \texttt{M-x shell} (these will be useful later
for running R wihin Emacs.)
\item Any text you care for \ldots{} \texttt{M-x animate-birthday-present}
\end{enumerate}
\item Switching between buffers from \texttt{Buffers} menu or \texttt{C-x b}
\item Think of buffers as bits of text that can be edited/moved around.
\item You can easily get 100+ buffers on a good day\ldots{}!
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Windows and frames}
\label{sec-2-17}


\begin{itemize}
\item A \emph{frame} can have one or more windows.
\item An emacs process can create many frames (e.g. \texttt{M-x speedbar}, \texttt{C-x 5 2})
\item Each window has a \emph{modeline} (describe).
\item Each frame usually has an echo area, and a minibuffer. These
normally overlap.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Major and minor modes}
\label{sec-2-18}


Modes contain specialisations (commands/variables) for different
languages.

\begin{itemize}
\item Major modes are defined for different languages (C, latex, R,
python, \ldots{}).
\item Consistency across modes where possible (e.g. commands for
commenting, indentation). Keybindings consistent. \emph{Font lock}
also consistent, e.g. comments in red.
\item Only one \emph{major} mode active at a time (?Sweave?)
\item Major mode decided typically on regexps on buffer name.
\end{itemize}

See \texttt{C-h v auto-mode-alist}

\begin{itemize}
\item Can have several \emph{minor} modes, e.g. auto-fill-mode,
flyspell-mode, font-lock-mode. Try \texttt{M-x tool-bar-mode}
\item \texttt{C-h m} describes features available in current buffer.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Completion, defaults, history}
\label{sec-2-19}


\begin{itemize}
\item TAB completion where possible, e.g \texttt{M-x describe- TAB}
\item sensible defaults, depending on text at point. e.g. \texttt{M-x man} with
point on word \emph{perl}
\item context-dependent history, e.g. \texttt{M-x <up>} to see prev commands, or
\texttt{M-x man RET <up>} to see previous man pages.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Getting help with Emacs}
\label{sec-2-20}



\begin{center}
\begin{tabular}{ll}
\hline
Keybinding & Function \\
\hline
C-h m & describe mode \\
C-h k & describe key \\
C-h i & info \\
C-h t & tutorial \\
\hline
\end{tabular}
\end{center}




Check out \href{http://emacswiki.org}{http://emacswiki.org}
\end{frame}
\begin{frame}
\frametitle{Some of my favourite Emacs things}
\label{sec-2-21}


\begin{itemize}
\item (show-paren-mode)
\item find file at point: ffap
\item iswitchb / ido
\item VC: version control \texttt{C-x v l}
\item ediff, e.g. \texttt{M-x ediff-revision}
\item \texttt{M-x occur RET eval}
\item \texttt{M-x grep}, \texttt{M-x compile} work similarly.
\item AUCTeX + reftex
\item org mode
\item GNUS / MH-E / VM / RMAIL
\item ESS !!!
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Changing how emacs works}
\label{sec-2-22}


``Emacs is the extensible, customizable, self-documenting real-time
display editor.'' (info ``emacs'')

\begin{itemize}
\item \emph{Extensible} means that you can extend by writing elisp. Most of
emacs is written in elisp, with C for core.
\item \emph{Customizable} means that you can change behaviour by changing
values of variables.
\item The .emacs file
\item Reload by restarting emacs, \texttt{M-x eval-buffer} or \texttt{M-x eval-region}
\item Or, after a closing bracket, just \texttt{C-x C-e}. Try twice e.g.:
\begin{verbatim}
(+ 5 (* 3 2) 4)
\end{verbatim}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{How does Emacs find its libraries?}
\label{sec-2-23}


\begin{itemize}
\item Emacs' \texttt{load-path} controls which directories are searched.
\end{itemize}

\begin{verbatim}
(locate-library "ess")
(add-to-list 'load-path "~/langs/emacs/org-mode/lisp")
\end{verbatim}

Or to look up the definition of a function, try \texttt{M-x find-function ess-dirs}.
\end{frame}
\begin{frame}
\frametitle{How do you find other packages?}
\label{sec-2-24}


\begin{itemize}
\item \href{http://emacswiki.org}{http://emacswiki.org} mentions many, and has repository.
\item Upcoming Emacs Lisp Package Archive (ELPA).
\item \href{http://www.damtp.cam.ac.uk/user/sje30/emacs/ell.html}{http://www.damtp.cam.ac.uk/user/sje30/emacs/ell.html}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Exercise: install Org mode 7.8.11}
\label{sec-2-25}


Although Emacs comes with org-mode, you probably should get a newer
version. 7.8.11 has been released, 2012-05-25

Download, unpack, make and install.
\begin{verbatim}
wget http://orgmode.org/org-7.8.11.tar.gz
tar xfz org-7.8.11.tar.gz
cd org-7.8.11
make ## not make install

Add to .emacs and eval.
\end{verbatim}

\begin{verbatim}
(add-to-list 'load-path "~/org-7.8.11/lisp")
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(require 'org-install)

C-h v org-version
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Exercise: make sure you have ESS 12.04-4 (or 12.04-2) if you can.}
\label{sec-2-26}


Installing ESS is slightly simpler, especially if you want just the
source.

Download, unpack, and then:
\begin{verbatim}
(load "~/langs/emacs/elisp-ds/ess/lisp/ess-site")
\end{verbatim}

Aug 2011: Vincent Goulet's pre-made binaries for MAC and WIN are up
to date.
\end{frame}
\begin{frame}[fragile]
\frametitle{Variables}
\label{sec-2-27}


Emacs variables influence the way functions behave.



\begin{verbatim}
(setq visibile-bell t)
\end{verbatim}

\begin{itemize}
\item nil is FALSE, everything else, including t, is TRUE.
\item \texttt{M-x customize}
\item \texttt{M-x customize-group RET ess RET}
\item \texttt{M-x customize-variable RET visible-bell RET}
\item Finding new variables and functions: \texttt{M-x apropos RET occur RET}
\item Hook variables \ldots{}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Hook variables}
\label{sec-2-28}



\begin{itemize}
\item Hooks are run e.g. after major-mode has been created.
\end{itemize}

\begin{verbatim}
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
\end{verbatim}

\begin{itemize}
\item Compare the following two versions:
\end{itemize}

\begin{verbatim}
## version 1
(defun my-ess-hook ()
"Add my keybindings to ESS mode."
(local-set-key (kbd "C-j") 'ess-eval-line-and-step))

(add-hook 'R-mode-hook 'my-ess-hook)

## version 2
(add-hook 'R-mode-hook
'(lambda () (local-set-key (kbd "M-RET")
'ess-R-use-this-dir)))
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Read (and edit) the source}
\label{sec-2-29}


\begin{itemize}
\item \texttt{M-x find-function RET shell RET}
\end{itemize}

Emacs is extensible: write your own functions. e.g.


\begin{verbatim}
(defun date-stamp ()
"Insert current date and time at point."
(interactive)
(insert (current-time-string)))
\end{verbatim}

\begin{itemize}
\item Notes: 1. \texttt{interactive} makes it available to \texttt{M-x}. 2. Doc string
accessible.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Byte compiler}
\label{sec-2-30}


\begin{itemize}
\item You will see .elc files; these are byte-compiled files.
\item \texttt{M-x byte-compile-file}
\item Should be faster than \texttt{.el} files, but can be confusing when
developing code to have both .el .elc around.
\item Note: \texttt{M-x find-function RET shell RET} will visit the
\emph{compressed} source file. Can edit .gz files as if they were
uncompressed.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Philosophy}
\label{sec-2-31}


\begin{itemize}
\item Keeping files in plain text. Unicode: (view-hello-file)
\item Keybindings should be consistent across modes.
\item Keep one Emacs running (e.g. for many days).
\item Where to draw the line about running everything in Emacs? mail?
web browsing? \texttt{M-x artist-mode}
\end{itemize}
\end{frame}
\section{part II: ESS}
\label{sec-3}
\begin{frame}
\frametitle{Why ESS?}
\label{sec-3-1}


Taken from the manual \texttt{(info "(ess)Features")}

\begin{itemize}
\item Command history, searchable + modifiable.
\item Command-line completion of both object and file names.
\item Hot-keys for quick entry of commonly-used commands in `S'.
\item Transcript recording for a complete record of session.
\item Interface to the help system.
\item Object editing.
\item Editing mode for code, providing syntactic indentation and highlighting.
\item evaluating lines/regions/chunks of R code.
\item loading and error-checking source files.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{History of ESS (Tony)}
\label{sec-3-2}


\begin{itemize}
\item 3 branches: S-mode, SAS-mode, Stata-mode
\item S-mode: 1989, 2 groups managing the project before (Bates/F
Ritter/E Kademan, M Meyer, DM Smith).
R added in 1995 (Rossini/Maechler)
\item SAS: `94, Tom Cook (`92, John Sall, SAS). Integrated `95-6, Rossini
\item Stata-mode: 1997, Thomas Lumley. Added 1997 (Rossini).
\item 1997: last major restructuring (``grand unification'')
\item 2004: switch leaders: Maechler takes over
\end{itemize}


\begin{itemize}
\item We are still suffering from the 1997 grand unification.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{ESS Installation}
\label{sec-3-3}


\begin{itemize}
\item \href{http://ess.r-project.org/index.php?Section=download}{http://ess.r-project.org/index.php?Section=download}
\item New users: grab pre-packaged bundle.
\item For those who prefer a mac-like app: \href{http://aquamacs.org/}{http://aquamacs.org/}
\item Debian package \emph{ess}
\item Available from Emacs Lisp Package Archive (ELPA) in near future
\item Line in .emacs:
\end{itemize}


\begin{verbatim}
(load "~/langs/emacs/elisp-ds/ess/lisp/ess-site")
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Editing and viewing R code}
\label{sec-3-4}


Indentation should be automatic; if in doubt \texttt{M-x indent-region}

\begin{itemize}
\item Imenu for browsing function definitons. (or use Speedbar)
\item Demo: view example code in \href{file://.files/ms_funs.R}{file:files/ms\_funs.R}
\item The magic underscore. like it? If not, Try M-q \_{} (this works in
general, e.g. M-q TAB). Or customize:
\end{itemize}


\begin{verbatim}
(ess-toggle-underscore nil)
\end{verbatim}

\begin{itemize}
\item \texttt{C-c TAB} does object completion within .R buffers
\item Moving around your functions:
\end{itemize}


\begin{center}
\begin{tabular}{ll}
\hline
Keybinding & Function \\
\hline
C-M-a & ess-beginning-of-function \\
C-M-e & ess-end-of-function \\
C-M-h & ess-mark-function \\
\hline
\end{tabular}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Making comments}
\label{sec-3-5}


\begin{itemize}
\item ESS follows the three-level comment model of elisp:
\begin{enumerate}
\item One hash (\#) for col 32 aligned end-of-line comments.
\item Two hashes (\#\#) to match current indentation.
\item Three hashes (\#\#\#) for column 0, major comments.
\end{enumerate}
See examples in \texttt{files/ms\_funs.R}
\item \texttt{comment-dwim} is bound to \texttt{M-;}.
\item This `do what I mean' should work well for cases 1 and 2.
\item Or use \texttt{comment-region} (with or without prefix).
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Indenting your code.}
\label{sec-3-6}


\begin{itemize}
\item By default, ESS uses a set of variables to set spacing.
\item Following from \texttt{(info "(ess)Styles")}
\end{itemize}

\begin{quote}
The combined value of nine variables that control indentation are
collectively termed a style. ESS provides several styles covering the
common styles of indentation: `DEFAULT', `OWN', `GNU', `BSD', `K\&R',
`C++', `RRR', `CLB'. The variable `ess-style-alist' lists the value of
each indentation variable per style.
\end{quote}

\begin{itemize}
\item To reindent code: \texttt{M-x indent-region}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Viewing help files}
\label{sec-3-7}


e.g. \texttt{C-c C-v RET pbinom RET} (or ?pbinorm within \verb~*R*~).
Key features

\begin{itemize}
\item move easily between sections (n/p)
\item browse help for new pages
\item running examples (l)
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Making help files (.Rd)}
\label{sec-3-8}


\begin{itemize}
\item Edit an exiting .Rd file: \href{file:///u/maechler/R/Meetings-Kurse-etc/2012-Nashville/ESS-tutorial/ess2012/files/sjedrp.Rd}{file:files/sjedrp.Rd}
\item Create a new file. \href{file://.files/empty.Rd}{file:files/empty.Rd} then \texttt{C-c C-e}
\item Preview your Rd files \texttt{C-c C-p}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Inferior ESS Processes (\verb~*R*~)}
\label{sec-3-9}


\begin{itemize}
\item \texttt{M-x R} will start an R process within a new buffer.
\item We can have multuple R processes, running either locally or remotely.
\item Passing command-line switches to the R session.
\end{itemize}

\begin{verbatim}
C-u M-x R RET --no-save RET
\end{verbatim}


\begin{verbatim}
(setq inferior-R-args "--no-save ")
\end{verbatim}

\begin{itemize}
\item These buffers are called \emph{inferior} as they run a process under
Emacs. Our ESS manual calls them \emph{iESS} buffers.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Which version of R will it find?}
\label{sec-3-10}


\begin{itemize}
\item Should find all versions of R on your path, see the list found by
\begin{verbatim}
M-x R- TAB
\end{verbatim}
\item If you have a version of R on your path, try putting in a symlink
somewhere on your path.

\begin{verbatim}
ln -s /my/version/of/R ~/bin/R-2.15.0-special
\end{verbatim}
\item Which versions of R are found?
\end{itemize}
\begin{verbatim}
ess-r-versions is a variable defined in `ess-r-d.el'.
Its value is ("R-1" "R-2" "R-devel" "R-patched")
\end{verbatim}

\begin{itemize}
\item \texttt{M-x R-newest} will be bound to newest version of R on your
system, by checking \texttt{R -{}-version} for each R binary.
\item (Windows might differ slightly)
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{What can I do in \texttt{*R*}?}
\label{sec-3-11}


\begin{itemize}
\item Run commands as normal.
\item TAB Completion of functions, objects, filenames.
\item At the prompt, recall history:
\end{itemize}


\begin{center}
\begin{tabular}{ll}
\hline
keybinding & function \\
\hline
M-p & comint-previous-input \\
M-n & comint-next-input \\
M-r & comint-previous-matching-input \\
\hline
\end{tabular}
\end{center}



\begin{itemize}
\item Can move through \texttt{*R*} and resissue commands from previous prompts
\end{itemize}


\begin{center}
\begin{tabular}{ll}
\hline
keybinding & function \\
\hline
RET & inferior-ess-send-input \\
C-c RET & comint-copy-old-input \\
M-RET & ess-transcript-send-command-and-move \\
\hline
\end{tabular}
\end{center}
\end{frame}
\begin{frame}[fragile]
\frametitle{What is emacsclient?}
\label{sec-3-12}


Why does \texttt{*R*} start with:

\begin{verbatim}
options(STERM='iESS', editor='emacsclient')
\end{verbatim}

\begin{itemize}
\item emacsclient allows you to work with a running emacs, rather than
start a new one.
\end{itemize}

\begin{verbatim}
M-x server-start
% emacsclient file.R
\end{verbatim}

\begin{itemize}
\item Now in R, you can do things like
\end{itemize}


\begin{verbatim}
x <- rbinom(100, 10, 0.5)
edit(x)
fix(x)
page(x)
\end{verbatim}

\begin{itemize}
\item \texttt{C-x \#} should kill any client buffer.
\item As an aside, \texttt{emacsclient -t} will bring up a new window.
\item Warning: make sure you are using the right emacsclient if you have
several versions on your system.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{emacsclient / 2}
\label{sec-3-13}


\begin{itemize}
\item emacsclient allows you to run elisp
\end{itemize}


\begin{verbatim}
ess-slides.pdf: ess-slides.org
emacsclient --eval "(org-to-pdf \"ess-slides.org\")"
\end{verbatim}


\begin{verbatim}
(defun org-to-pdf (org)
"Convert org buffer ORG to a pdf."
(interactive)
(save-current-buffer
(set-buffer org)
(org-export-as-pdf t)))
\end{verbatim}
\end{frame}
\begin{frame}
\frametitle{Transcripts}
\label{sec-3-14}


\begin{itemize}
\item If you save an \texttt{*R*} buffer, you create a transcript.
\item You can keep using it.
\item Clean up transcripts: \texttt{M-x ess-transcript-clean-buffer}
\item Example \texttt{files/short\_session.Rt}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{How many versions of R can I run?}
\label{sec-3-15}


\begin{itemize}
\item \texttt{M-x R} multiple times will generate multiple processes,
e.g. \texttt{*R*}, \texttt{*R:2*}, \ldots{}
\item You can tell your .R buffer to use a particular session by \texttt{C-c C-s} and be prompted (with completion!) for R process.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Remote R sessions}
\label{sec-3-16}


\begin{itemize}
\item login to remote computer via, e.g. by a ssh command in \texttt{M-x shell}
\item Call \texttt{M-x ess-remote}, and select R.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Sending code from an R buffer to \texttt{*R*}}
\label{sec-3-17}


\begin{itemize}
\item An R source buffer must be associated with an iESS process. You
can do this with, \texttt{C-c C-s} or accept default association.
\item Loading source files with \texttt{C-c C-l}; errors can be parsed with
\texttt{C-c `}
\end{itemize}


\begin{center}
\begin{tabular}{ll}
\hline
Keybinding & Function \\
\hline
\texttt{C-c C-j} & \texttt{ess-eval-line} \\
\texttt{C-c M-j} & \texttt{ess-eval-line-and-go} \\
\texttt{C-c C-f} & \texttt{ess-eval-function} \\
\texttt{C-c M-f} & \texttt{ess-eval-function-and-go} \\
\texttt{C-c C-r} & \texttt{ess-eval-region} \\
\texttt{C-c M-r} & \texttt{ess-eval-region-and-go} \\
\texttt{C-c C-b} & \texttt{ess-eval-buffer} \\
\texttt{C-c M-b} & \texttt{ess-eval-buffer-and-go} \\
\texttt{C-c C-n} & \texttt{ess-eval-line-and-step} \\
\hline
\end{tabular}
\end{center}




\begin{itemize}
\item \texttt{C-c C-y} will switch to end of iESS buffer.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Sending code to \texttt{*R*} --- is it slow?}
\label{sec-3-18}


If so, this is a long-standing bug. Add:


\begin{verbatim}
(setq ess-eval-visibly-p nil)
\end{verbatim}
\end{frame}
\begin{frame}
\frametitle{Narrowing}
\label{sec-3-19}


\begin{itemize}
\item You can temporarily narrow a buffer down to a particular region,
and then \texttt{C-c C-b} works on that narrowed region:
\item \texttt{M-x narrow-to-region C-x n n}
\item \texttt{M-x narrow-to-defun C-x n d} works for R source buffers.
\item \texttt{M-x widen C-x n w}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Customizing ESS}
\label{sec-3-20}


Recommended way is to do:

\begin{verbatim}
(customize-group 'ess)
\end{verbatim}

or try editing your .emacs. e.g.

\begin{verbatim}
(setq ess-ask-for-ess-directory nil)
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{When things go wrong with ESS}
\label{sec-3-21}


\begin{itemize}
\item Read the info guides for sending bug reports
\end{itemize}

\begin{verbatim}
(info "(ess)Reporting Bugs")
\end{verbatim}

\begin{itemize}
\item ess-help mailing list
\item \href{http://www.emacswiki.org/emacs/EmacsSpeaksStatistics}{http://www.emacswiki.org/emacs/EmacsSpeaksStatistics}
\end{itemize}
\end{frame}
\section{Part III: Sweave}
\label{sec-4}
\begin{frame}
\frametitle{Literate Programming}
\label{sec-4-1}


From the web page describing his book \emph{Literate Programming}, Donald E
Knuth writes:

``Literate programming is a methodology that combines a programming
language with a documentation language, thereby making programs more
robust, more portable, more easily maintained, and arguably more fun
to write than programs that are written only in a high-level
language. The main idea is to treat a program as a piece of
literature, addressed to human beings rather than to a computer. The
program is also viewed as a hypertext document, rather like the World
Wide Web. (Indeed, I used the word WEB for this purpose long before
CERN grabbed it!) \ldots{}''

\url{http://www-cs-faculty.stanford.edu/~uno/lp.html}
\end{frame}
\begin{frame}[fragile]
\frametitle{Tangling and Weaving:}
\label{sec-4-2}


\begin{itemize}
\item CWEB: system for documenting C, C++, Java:
\end{itemize}

\begin{verbatim}
CTANGLE
converts a source file foo.w to a compilable program file foo.c;
CWEAVE
converts a source file foo.w to a prettily-printable and
cross-indexed document file foo.tex.
\end{verbatim}
\url{http://sunburn.stanford.edu/~knuth/cweb.html}
\end{frame}
\begin{frame}
\frametitle{What is Reproducible Research (RR)?}
\label{sec-4-3}


\begin{itemize}
\item Gentleman et al (2004) advocate RR:
\end{itemize}

\begin{quote}
Buckheit and Donoho (35) , referring to the work and philosophy of
Claerbout, state the following principle: ``An article about
computational science in a scientific publication is not the
scholarship itself, it is merely advertising of the
scholarship. The actual scholarship is the complete software
development environment and that complete set of instructions that
generated the figures.''
\end{quote}

\url{http://genomebiology.com/2004/5/10/R80}

\begin{itemize}
\item Bioconductor packages are good examples of reproducible research.
\item This article is also good background reader for open software
development.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Sweave: literate programming for R}
\label{sec-4-4}


\begin{itemize}
\item Sweave is the system for mixing latex and R code in the same
document.
\item Used within R often to create ``vignettes'' which can be
dynamically run.
\item Allows you to write reports where results (tables,graphs) are
automatically generated by your R code.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Sweave: including code chunks}
\label{sec-4-5}


\begin{itemize}
\item An example code chunk: by default we are in `LaTeX mode'.
\end{itemize}


\begin{verbatim}
We can then test the procedure a few
times, using the default number
of darts, 1000:

<<>>=
replicate(9, estimate.pi())
@
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Sweave: including graphs}
\label{sec-4-6}


\begin{itemize}
\item Automatically creates filenames, e.g. \verb~estimate-001.pdf~
\item By default will generate .ps and .pdf; so change options:
\end{itemize}
\begin{verbatim}
\SweaveOpts{echo=T,pdf=T,eps=F,eval=T,keep.source=T}
\end{verbatim}


\begin{verbatim}
\setkeys{Gin}{width=0.6\textwidth}
\begin{center}
<<fig=TRUE>>=
r <- 1; n <- 50; par(las=1)
plot(NA, xlim=c(-r,r), ylim=c(-r,r), asp=1, bty='n',
xaxt='n', yaxt='n', xlab='', ylab='')
axis(1, at=c(-r,0,r)); axis(2, at=c(-r,0,r))
symbols(x=0, y=0, circles=r, inch=F, add=T)
...
rect(-r, -r, r, r, border='blue', lwd=2)
@
\end{center}
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Sweave: including tables}
\label{sec-4-7}


\begin{itemize}
\item Use the \emph{xtable} package from CRAN.
\item Example from that package:
\end{itemize}



\begin{verbatim}
<<echo=FALSE>>=
library(xtable)
data(tli)
@

<<label=tab1,echo=FALSE,results=tex>>=
## Demonstrate data.frame
tli.table <- xtable(tli[1:20,])
digits(tli.table)[c(2,6)] <- 0
print(tli.table)
@
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Sweave: including inline computation}
\label{sec-4-8}



\begin{verbatim}
In this case the number of darts within
the circle is \Sexpr{d}, and so the estimated
value is $\pi \approx \Sexpr{4*d/n}$.
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Sweave: a full example}
\label{sec-4-9}

\begin{itemize}
\item Example application: estimate the value of $\pi$ using the
\end{itemize}
dartboard method.
\begin{itemize}
\item \href{file://.~/papers/2009_R/estimate.Rnw}{estimate.Rnw}
\item For nice ways to customize Sweave output (as in estimate.Rnw:
\end{itemize}
\url{http://www.stat.auckland.ac.nz/~stat782/downloads/Sweave-customisation.pdf}

\begin{itemize}
\item Compiling the document with make:
\end{itemize}


\begin{verbatim}
estimate.pdf: estimate.Rnw
R CMD Sweave estimate.Rnw
pdflatex estimate.tex
\end{verbatim}

\begin{itemize}
\item Note: \texttt{R CMD Sweave -{}-pdf} (since R 2.14.0)
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Emacs and Sweave: how to get n>1 major-mode?}
\label{sec-4-10}


\begin{itemize}
\item How can we switch between major modes within the same buffer?
\item Approach: R-mode for code chunks, AUCTeX for latex sections.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Why AUCTeX?}
\label{sec-4-11}


\begin{itemize}
\item \href{http://www.gnu.org/software/auctex/}{http://www.gnu.org/software/auctex/}
\item Excellent environment for (1) editing, (2) compiling and (3) viewing output.
\item Shortcuts for inserting environments, blocks, and for completion.
\item Interacts well with bibtex too.
\item Reftex allows for easy editing/viewing of citations,
table-of-contents. (Carsten Dominik).
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Exercise: compile/edit a document in AUCTeX}
\label{sec-4-12}


\begin{itemize}
\item Warning: may need to install AUCTeX
\end{itemize}

See example \href{file:///u/maechler/R/Meetings-Kurse-etc/2012-Nashville/ESS-tutorial/ess2012/coin/coin.tex}{file:coin/coin.tex} and try the following

\begin{itemize}
\item edit it, compile it, fix errors.
\item What do these commands do? \texttt{C-c [} \texttt{C-c \&}
\item Browse the TOC: \texttt{C-c =}
\item I prefer to generate PDF (rather than postcript): \texttt{C-c C-t C-p}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Makefiles / compile modes.}
\label{sec-4-13}


\begin{itemize}
\item One approach to compiling your document is to use Makefiles.
\item Emacs can run these with \texttt{M-x compile}
\item Output shown in own buffer, which can be parsed.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Sweave editing help}
\label{sec-4-14}


\begin{itemize}
\item Typing \texttt{<} at start of line is \emph{electric} and will expand to:
\end{itemize}


\begin{verbatim}
<<>>=
@
\end{verbatim}

\begin{itemize}
\item Has many functions for navigating around and moving chunks. See the
Noweb menu.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Sweave compilation}
\label{sec-4-15}


\begin{itemize}
\item `M-n s' (`ess-swv-weave')
Run Sweave on the current .Rnw file.
\item `M-n l' (`ess-swv-latex')
Run \LaTeX{} after Sweave'ing.
\item `M-n p' (`ess-swv-PS')
Generate and display a postscript file after LaTeX'ing.
\item `M-n P' (`ess-swv-PDF')
Generate and display a PDF file after
LaTeX'ing. The command used to generate the PDF file is the
first element of `ess-swv-pdflatex-commands'.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Sweave + AUCTeX}
\label{sec-4-16}


This needs to be added in .emacs before place you load ESS, then
restart Emacs. (\textbf{New since ESS 5.14.})


\begin{verbatim}
(setq ess-swv-plug-into-AUCTeX-p t)
\end{verbatim}

\begin{itemize}
\item Within an R buffer, \texttt{C-c C-c Sweave} runs Sweave in a separate
process, not \texttt{*R*}.
\item Compile latex file with \texttt{C-c C-c LaTeXSweave}.
\item View resulting file with \texttt{C-c C-c View}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{How it works in Emacs (advanced)}
\label{sec-4-17}


\begin{itemize}
\item multiple-major modes is quite fragile; more principled approaches
welcome, e.g. based on Dave Love's work (indirect buffers).
\item Current approach assumes that every time you switch in/out of a
chunk, the major mode is reset; any local variable modifications
must be set in hooks.
\end{itemize}
\end{frame}
\section{Part IV: Org mode}
\label{sec-5}
\begin{frame}[fragile]
\frametitle{Prelim: make sure you have Org installed, see earlier section.}
\label{sec-5-1}



\begin{verbatim}
(require 'org-install)
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{My org mode setup}
\label{sec-5-2}


\begin{verbatim}
(add-to-list 'load-path "~/langs/emacs/elisp-ds/org-mode/lisp")
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(setq org-completion-use-iswitchb t)
(global-set-key "\C-cb" 'org-iswitchb)

;; stop C-c C-c within code blocks from querying
(setq org-confirm-babel-evaluate nil)

;; which languages do I want??
(org-babel-do-load-languages
'org-babel-load-languages
'((R . t)
(sh . t)
(emacs-lisp . t)
))
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{Live demo !}
\label{sec-5-3}


\begin{itemize}
\item Follow demo in \href{file:///u/maechler/R/Meetings-Kurse-etc/2012-Nashville/ESS-tutorial/ess2012/org/intro.org}{file:org/intro.org}
\item simple outlining: folding/ moving/ promoting+demoting
\item simple markup, e.g. \textbf{bold} \emph{italics} \underline{underscore} and \verb~verbatim~
\item editing lists
\item look how math is formatted\ldots{} $\alpha$ + $\beta$ without the need for
math mode?
\item tables; spreadsheets.
\item export
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Other key features of org mode (not covered here)}
\label{sec-5-4}


\begin{itemize}
\item agendas, dates.
\item scheduler
\item clocking tasks
\item todo lists
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Including code snippets}
\label{sec-5-5}



\begin{verbatim}
#+begin_src R :exports both :results graphics :file hist.png
hist( rnorm(1e4))
#+end_src
\end{verbatim}

These enviroments can be added using ``Easy Templates'', e.g. \texttt{< s TAB}
to get a source block.

These code snippets can be run using \texttt{C-c C-c} to generate results
after the code snippet. see ob-R-examples.org
\end{frame}
\begin{frame}
\frametitle{Exercise: Org examples to explore}
\label{sec-5-6}


\begin{enumerate}
\item \href{file:///u/maechler/R/Meetings-Kurse-etc/2012-Nashville/ESS-tutorial/ess2012/org/nice/nice.org}{file:org/nice/nice.org} and export it to either latex -->
pdf or html (\texttt{C-c C-e} for export menu)

\href{http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html}{http://emacs-fu.blogspot.com/2011/04/nice-looking-pdfs-with-org-mode-and.html}
\item \href{file:///u/maechler/R/Meetings-Kurse-etc/2012-Nashville/ESS-tutorial/ess2012/org/drift/drift.org}{file:org/drift/drift.org} -- Genetic drift. For browsing and
exporting.

\href{http://orgmode.org/worg/org-contrib/babel/uses.html}{http://orgmode.org/worg/org-contrib/babel/uses.html}
\end{enumerate}


\begin{enumerate}
\item ob-R-examples.org -- Some simple examples in R, to run and export.
\item CISE -- convert this to use R rather than gnuplot. Or try to
get the baseball stats for year other than 2010.

Eric Schulte, Dan Davison. Active Documents with Org-Mode
Computing in Science \& Engineering 2011.

\href{http://www.cs.unm.edu/~eschulte/data/CISE-13-3-SciProg.pdf}{http://www.cs.unm.edu/\~eschulte/data/CISE-13-3-SciProg.pdf}
\end{enumerate}
\end{frame}
\begin{frame}
\frametitle{Problems with org-mode for RR}
\label{sec-5-7}


\begin{enumerate}
\item Is it prime for RR yet?
\item Emacs 24 as stable base for documents\ldots{}
\item Tom Dye has a nice reproducible solution for Org config.
\href{https://github.com/tsdye/hawaii-colonization}{https://github.com/tsdye/hawaii-colonization}
\item How do \textbf{you} think it compares with sweave?
\end{enumerate}
\end{frame}
\section{Advanced topics}
\label{sec-6}
\begin{frame}
\frametitle{Speedbar support for R code / imenu}
\label{sec-6-1}


\begin{itemize}
\item \texttt{M-x speedbar}
\item Driven by the imenu support, which in turn depends on
\texttt{ess-imenu-S-generic-expression} which you see has \texttt{<-}
hard-coded.
\item Show examples in \texttt{files/ms\_funs.R}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Support for editing Roxygen documentation.}
\label{sec-6-2}


\begin{itemize}
\item See info node for full details: \texttt{(info "(ess)Roxygen")}
\end{itemize}


\begin{verbatim}
##' Description of the function
##'
##' Further details about this function
##' @title A title
##' @param me all parameters must be listed and documented
##' @return Description of the return value
##' @author The author
myfun <- function(me)
cat("Hello", me, "\n")
@end verbatim
\end{verbatim}
\end{frame}
\begin{frame}[fragile]
\frametitle{TAGS support}
\label{sec-6-3}


\begin{itemize}
\item TAGS files are supported for many different editing modes.
\item They contain a list of where functions are defined in your source
file.
\item Normally found by regexps, but R now can generate tags directly:

\begin{verbatim}
R CMD rtags --help
\end{verbatim}
\item You can then ask Emacs to find definition of function name under
point.
\item \texttt{(info "(ess)TAGS")}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{ESS-rdired}
\label{sec-6-4}


\begin{itemize}
\item Mode inspired by Dired for files.
\item For viewing objects, deleting, plotting.
\item \texttt{(info "(ess)Rdired")}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Rutils}
\label{sec-6-5}

\begin{itemize}
\item Recent addition to ESS, building upon ess-rdired. Adds many convenience functions.
\item Browsing, adding, updating packages
\item Editing objects
\item Managing workspaces
\item \texttt{(info "(ess)Rutils")}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\frametitle{Dynamically showing arguments of a function}
\label{sec-6-6}


Both of these methods work by calling the R function \texttt{args()} with
function name under point. What differs is the feedback mechanism.
\begin{itemize}

\item ess-eldoc, works like other eldoc modes, e.g. elisp.\\
\label{sec-6-6-1}%
\href{file://.example.R}{Eldoc example}


\begin{verbatim}
(require 'ess-eldoc)
(add-hook 'inferior-ess-mode-hook 'ess-use-eldoc)
\end{verbatim}


\item ess-r-args-show\\
\label{sec-6-6-2}%
\begin{verbatim}
;; bind ess-r-args-show to F2
(define-key ess-mode-map [f2] 'ess-r-args-show)
\end{verbatim}

\end{itemize} % ends low level
\end{frame}
\begin{frame}
\frametitle{r-autoyas}
\label{sec-6-7}


\begin{itemize}
\item \href{http://www.svenhartenstein.de/Software/R-autoyas}{http://www.svenhartenstein.de/Software/R-autoyas}
\item Dynamically creates \emph{snippets} for editing R functions. Watch the
movie online at:

\href{http://www.youtube.com/watch?v=jLJPorf2LBE}{http://www.youtube.com/watch?v=jLJPorf2LBE}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Debuggers}
\label{sec-6-8}


\begin{enumerate}
\item Since ESS 12.03, \emph{Ess-tracebug} is part of ESS:
``A package for interactive visual debugging of R
code from ESS. It provides visual debugging, browser, recover and
conditional breakpoints; watch window and loggers; interactive
debug/undebug of R functions and methods at point; highlighting
and easy error navigation and interactive traceback.''
Docu \href{http://code.google.com/p/ess-tracebug/}{http://code.google.com/p/ess-tracebug/}
\item There are \textbf{R} packages for enhanced debugging, notably \emph{edtdbg}
``integrates R's debugging facilities with your
text editor, featuring code tracking, variable display, quick
breakpoint setting, and easy toggling of function debug status.''
It provides support for both Emacs and VIM. Package available
from CRAN mirrors.
\end{enumerate}
\end{frame}
\begin{frame}
\frametitle{R Object Tooltips in ESS}
\label{sec-6-9}


\begin{itemize}
\item Watch the movie to see the tooltips for object at point:
\href{http://www.sigmafield.org/2009/10/01/r-object-tooltips-in-ess}{http://www.sigmafield.org/2009/10/01/r-object-tooltips-in-ess}
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Rewrite of interface to inferior processes (SLIME)}
\label{sec-6-10}


\begin{itemize}
\item ESS uses comint to interface with R processes.
\item Better solution, based on sockets, rather than text-based
channels, is to use SLIME framework.
\item Work in progress (Christophe Rhodes):

\href{http://common-lisp.net/~crhodes/swankr/}{http://common-lisp.net/\~crhodes/swankr/}
\end{itemize}
\end{frame}
\section{Part V Future steps / Q \& A session / open discussion}
\label{sec-7}
\begin{frame}
\frametitle{Final discussion}
\label{sec-7-1}


\begin{itemize}
\item What would you like to ask?
\item e.g. Can I do X with Emacs / ESS?
\item What is the focus for future development of ESS?
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Further reading}
\label{sec-7-2}


\begin{enumerate}
\item \emph{Intro to emacs lisp} is a great introduction to learning elisp.
\item \emph{Org mode} manual. Warning: it is big! You might prefer the
`compact' guide: \href{http://orgmode.org/guide/index.html}{http://orgmode.org/guide/index.html}
\end{enumerate}
\end{frame}
\section{End}
\label{sec-8}
\begin{frame}
\frametitle{My contact details}
\label{sec-8-1}


\begin{itemize}
\item Stephen Eglen
\item sje30@cam.ac.uk
\item Tel: 01223 765761
\item Web: \href{http://www.damtp.cam.ac.uk/user/sje30/}{http://www.damtp.cam.ac.uk/user/sje30/}
\end{itemize}
\end{frame}

\end{document}

Hint: I prefer to edit the wiki using the "Raw edit" button below; this provides a simple text box, and forces the use of wiki syntax. Use the "Attach" button below to upload files. There are some wiki text formatting rule here: TextFormattingRules

  • new.r: graphics R script file from tutorial

  • new.Rout: transcript file from graohcs example
Topic attachments
I Attachment Action Size Date Who CommentSorted ascending
demo.rr demo.r manage 0.1 K 12 Jun 2012 - 08:26 RichHeiberger  
fake.plot.data.frame-setup.rr fake.plot.data.frame-setup.r manage 0.9 K 12 Jun 2012 - 08:25 RichHeiberger  
fake.plot.data.frame.rr fake.plot.data.frame.r manage 0.1 K 12 Jun 2012 - 08:25 RichHeiberger  
rmhslides.pdfpdf rmhslides.pdf manage 29.5 K 12 Jun 2012 - 08:26 RichHeiberger  
tmp.rr tmp.r manage 0.1 K 12 Jun 2012 - 08:25 RichHeiberger  
Sweave-Example-collection.orgorg Sweave-Example-collection.org manage 1.3 K 12 Jun 2012 - 11:47 RichHeiberger Collection of Martin's Sweave examples
new.rr new.r manage 0.5 K 14 Jun 2012 - 12:11 RichHeiberger graphics R script file from tutorial
ess-slides.orgorg ess-slides.org manage 37.2 K 11 Jun 2012 - 22:07 RichHeiberger Org-mode "Source" of the slides
ess-slides.pdfpdf ess-slides.pdf manage 713.1 K 12 Jun 2012 - 06:25 RichHeiberger PDF / Presentation "version" of slides
ggraph.pdfpdf ggraph.pdf manage 1109.4 K 12 Jun 2012 - 11:49 RichHeiberger the paper produced from the ggraph.Rnw Sweave example
Sweave-Example-collection_files.zipzip Sweave-Example-collection_files.zip manage 48.4 K 12 Jun 2012 - 11:48 RichHeiberger the Rnw source files of the collection
new.RoutRout new.Rout manage 2.6 K 14 Jun 2012 - 12:12 RichHeiberger transcript file from graohcs example
Topic revision: r10 - 14 Jun 2012, RichHeiberger
 

This site is powered by FoswikiCopyright © 2013-2022 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Vanderbilt Biostatistics Wiki? Send feedback