Skip to content
Branch: master
Find file History
Grant Rettke
Grant Rettke Typo fix
Latest commit 8d05d96 Nov 29, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
BodyImage.Rnw Renamed folder Jun 3, 2018
BodyImage.bib Renamed folder Jun 3, 2018 Updated ESS settings for Body Image paper Nov 17, 2018
BodyImage.tex Updated ESS settings for Body Image paper Nov 17, 2018
BodyScale.png Renamed folder Jun 3, 2018
attractiveness.pdf Updated ESS settings for Body Image paper Nov 17, 2018
body_image.csv Renamed folder Jun 3, 2018
init.el Updated init.el file Aug 19, 2018
openbook_1000x647.jpg Renamed folder Jun 3, 2018
playboy.png Renamed folder Jun 3, 2018 Typo fix Nov 29, 2018

Using R with Emacs and ESS - A Multi-functional Environment

This Org file explains the Emacs configuration to write code in the R langues in Emacs. For more information go to The Devil is in the Data.

This org file shows the elisp code for a minimal configuration to write R code in Emacs. You can write all relevant code to an init file (tangle) with the C-c C-v C-t keystrokes.

Installing packages

This first snippet adds the Melpa repository and installs the required packages, but it is not saved to the init file as we only need to execute this once. Press C-c C-c to evaluate this code block. ESS will ask confirmation to run the code.

; Configure repository
(require 'package)
(add-to-list 'package-archives '("melpa" . ""))
; list the packages
(setq package-list
    '(ess ess-smart-underscore org-ref auto-complete))

; activate all the packages

; fetch the list of packages available 
(unless package-archive-contents

; install the missing packages
(dolist (package package-list)
  (unless (package-installed-p package)
    (package-install package)))

Configure ESS

Emacs Speaks Statistics (ESS) supports editing of scripts and interaction with various statistical analysis programs such as R. You also need to install the R software. You can start an R terminal with M-x R and enter the preferred working directory.

In ESS, the underscore key is mapped to the <- assignment operator in R. If you need an underscore, you need to type it twice. This functionality can be annoying when you are an avid user of ggplot. The ess-smart-underscore package solves this issue by allowing a single underscore in certain circumstances.

(require 'ess-site)
(require 'ess-smart-underscore)

Org Babel

Org Babel is the enables literate programming, including the functionality in this file.

;; Active the R language in Babel
 '((R . t)))

Auto complete

;; Auto complete
(require 'auto-complete-config)

Org LaTeX and BibTeX

;;Org BibTeX references
(require 'org-ref)
(org-ref-define-citation-link "citeA" ?a)
(setq org-latex-pdf-process
      '("pdflatex -interaction nonstopmode -output-directory %o %f"
	"bibtex %b"
	"pdflatex -interaction nonstopmode -output-directory %o %f"

;; Org Mode Latex Templates
(require 'ox-latex)

;; American Psychological Association papers
(add-to-list 'org-latex-classes '("apa6"
    "\\documentclass[a4paper, jou]{apa6}
	       ("\\section{%s}" . "\\section*{%s}")
	       ("\\subsection{%s}" . "\\subsection*{%Rs}")
You can’t perform that action at this time.