## I Wasted Time with a Custom Prompt for R with ESS

I wanted a custom prompt for R with ESS. I wanted a double struck R. I probably did it wrong. It never worked. Actually it worked most of the time, and that is worse than never working. Kind people helped me. I still got it wrong. I take full responsibility. It was better not to do it. If you want to try, here is where I left it.

.Rprofile

Make the ℝ prompt stand out (be sure to tell ESS how to handle this):

options(prompt="ℝ> ")


.emacs.el

Tell ESS how to handle my custom prompt:

(setq inferior-ess-primary-prompt "ℝ> ")


Handle the custom ℝ prompt in ess. Don’t use custom here.

(setq inferior-S-prompt "[]a-zA-Z0-9.[]*\$$?:[>+.] \$$*ℝ+> ")


## How to Format Magrittr Chains with ESS

Here is an example of how to format magrittr chains with ESS. Those interested will also be happy to learn of ess-R-fl-keyword:%op% and ess-%op%-face.

For example, to get the an indent after only the first statement.

(add-to-list 'ess-style-alist
'(my-style
(ess-indent-level . 4)
(ess-first-continued-statement-offset . 2)
(ess-continued-statement-offset . 0)
(ess-brace-offset . -4)
(ess-expression-offset . 4)
(ess-else-offset . 0)
(ess-close-brace-offset . 0)
(ess-brace-imaginary-offset . 0)
(ess-continued-brace-offset . 0)
(ess-arg-function-offset . 4)
(ess-arg-function-offset-new-line . '(4))
))

(setq ess-default-style 'my-style)


Thank you Mr. Vitalie Spinu.

How I did it:

(setq gcr/ess-style
(copy-alist
(assoc 'RRR ess-style-alist)))
(setf (nth 0 gcr/ess-style) 'GCR)
(setf (cdr
(assoc 'ess-continued-statement-offset
(cdr gcr/ess-style)))
0)
(setq ess-default-style 'GCR)


The latest version of ESS includes a RRR style.

It formats Magrittr chains as expected by default with ess-first-continued-statement-offset.

## eval-in-repl: Consistent ESS-like eval interface for various REPLs

This package does what ESS does for R for various REPLs, including ielm.

Emacs Speaks Statistics (ESS) package has a nice function called ess-eval-region-or-line-and-step, which is assigned to C-RET. This function sends a line or a selected region to the corresponding shell (R, Julia, Stata, etc) visibly. It also start up a shell if there is none.

This package implements similar work flow for various read-eval-print-loops (REPLs)

Via ess-help.

## How to install R on OSX 10.9 Mavericks as of 2014-06-01T19:29:55-0500

Here is how to install R on OSX 10.9 Mavericks as of 2014-06-01T19:29:55-0500:

brew install gcc
brew tap homebrew/science
brew install R


Details:

gcr@orion:~> gcc --version
gcc (GCC) 4.8.3
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gcr@orion:~> r --version
R version 3.1.0 (2014-04-10) -- "Spring Dance"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.2.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.


## Indenting new curly bracket blocks with smartparens for R

Emacs speaks statistics handle indentation for curly bracket blocks quite well. My preference was to have, after inserting matching opening and closing curly brackets, a newline with the cursor indented one block in. This post in particular describes the solution; it worked fine as of today.

Here is the code snippet from the above link:

(sp-local-pair 'c++-mode "{" nil :post-handlers '((my-create-newline-and-enter-sexp "RET")))

(defun my-create-newline-and-enter-sexp (&rest _ignored)
"Open a new brace or bracket expression, with relevant newlines and indent. "
(newline)
(indent-according-to-mode)
(forward-line -1)
(indent-according-to-mode))