1 #+TITLE: swankr: SWANK (and SLIME) for R
2 #+AUTHOR: Christophe Rhodes
3 #+EMAIL: csr21@cantab.net
5 This is swankr, an implementation of the swank[fn:1] protocol for
6 R[fn:2]. While the coverage of swank protocol functions is
7 currently limited, enough is implemented for swankr to be useful: at
8 the very minimum, it can be used to develop and extend itself.
9 ** Relationship with ESS
10 Emacs Speaks Statistics[fn:3] provides an interaction mode for R
11 (among other statistical software packages), including an interface
12 to R's toplevel, and keybindings to send input to R, to look up
13 documentation, and so on. Where it differs most noticeably from
14 swankr is in the level of integration of various facilities with
15 emacs: ESS uses the browser() debugger, whereas swankr provides its
16 own debugger, sldb; swankr provides a custom REPL with hooks for
17 common commands; and so on. For Lisp programmers, perhaps the most
18 useful analogy is to say that swankr is to ESS what SLIME is to
19 ILISP. At present, however, ESS mode remains active in R source
20 buffers, providing font-locking functionality among other things.
23 To begin using swankr:
25 2. load the swank.R file:
29 3. at the R prompt, run
33 4. within emacs, load and initialize slime;
34 5. run slime-connect, accepting the default host and port, and
35 acknowledging the protocol version mismatch.
36 At this point, a R REPL should appear.
37 ** Emacs customization
38 At a minimum, slime needs to be set up to function. I've
39 used the following forms in my =~/.emacs=
40 #+BEGIN_SRC emacs-lisp
42 (slime-setup '(slime-repl slime-scratch))
44 In addition, for keybindings like =C-c C-c= to work properly, emacs
45 needs to be told how to guess where a function definition begins.
46 This can be achieved with /e.g./
47 #+BEGIN_SRC emacs-lisp
48 (add-hook 'ess-mode-hook
50 (setq defun-prompt-regexp "^\\(\\(\\sw\\|\\s_\\)+\\|\\s\"\\S\"+\\s\"\\)\\s-*\\(=\\|<-\\)\\s-*function\\s-*(.*)\\s-*")))
52 Fontification of quoted function names is suboptimal by default in
53 ESS; the following form in =~/.emacs= fixes that for ESS 5.11.
54 #+BEGIN_SRC emacs-lisp
55 (eval-after-load "ess-common"
56 (setq ess-R-mode-font-lock-keywords
58 (list '("\\(\\sw\\|\\s_\\)+\\s-*\\(=\\|<-\\)\\s-*function"
59 1 font-lock-function-name-face t)
60 '("\\s\"\\(\\S\"+\\)\\s\"\\s-*\\(=\\|<-\\)\\s-*function"
61 1 font-lock-function-name-face t))
62 ess-R-mode-font-lock-keywords)))
65 swankr's primary development repository is a git repository,
67 <http://common-lisp.net/r/users/crhodes/swankr.git> and
68 git://common-lisp.net/crhodes/swankr/swankr.git; a web view of the
69 development history is [[http://common-lisp.net/gitweb?p=users/crhodes/swankr.git][available through gitweb]].
71 Thanks to my colleagues at [[http://www.gold.ac.uk/][Goldsmiths, University of London]], for
72 suggesting that I investigate R for numerical and graphical
73 investigations, and to my colleagues at [[http://www.teclo.net/][Teclo Networks AG]] for giving
74 me motivation to get around to it. Initial development was done at
75 the [[http://ismir2010.ismir.net/][International Symposium on Music Information Retrieval]], which I
76 attended (indirectly) thanks to the EPSRC-funded [[http://www.omras2.org/][OMRAS2]] research
77 project and the [[http://www.londoninternational.ac.uk][University of London External System]]; Helmut Eller's
78 partial implementation of swank for Ruby was an excellent blueprint
79 to get development started.
81 [fn:1] part of SLIME, the Superior Lisp Interaction Mode for Emacs:
82 <http://common-lisp.net/project/slime/>.
84 [fn:2] a free software environment for statistical computing and
85 graphics: <http://www.r-project.org/>.
87 [fn:3] also known as ESS, an emacs mode for interacting with a number
88 of statistical software packages, including R:
89 <http://ess.r-project.org/>.