2 min read

What to do if Emacs ESS can't find R

Emacs Speaks Statistics (ESS) is a powerful package that allows working from Emacs with many statistical systems, most notably R. If R is installed in a non-standard location, ESS may need to be told were to look for it. This post shows how this can be done, see also this question on Stackoverflow.

First, try adding the following line towards the beginning of your .emacs file:

(setq ess-directory-containing-R "c:/myPrograms")

where “c:/myPrograms” is the root of the tree where one or more versions of R are installed (change it to your actual folder). Restart Emacs and try Alt-X R to see if ESS can find the installed R versions.

If the above doesn’t work, read on.

For installation of Emacs I use the all-in-one installation file by Vincent Goulet. This is because it comes bundled with the advanced support for LaTeX and R, provided by AucTeX and ESS, as well as other packages needed for my workflow.

On Windows I have the habit of installing crucial programs under a directory with a short and easy to remember name without spaces, let’s say c:/myPrograms/. So Emacs would be in c:/myPrograms/Emacs. I also keep several versions of R, which I install under c:/myPrograms/R/. For example, R-3.6.3 and R-devel go to c:/myPrograms/R/R-3.6.3 and c:/myPrograms/R/R-devel, respectively.

When R is in a non-standard locations, ESS needs to be told were to look for it. This can be done by adding a line to file site-start.el in Emacs’ installation directory. For example, if Emacs is installed in c:/myPrograms/Emacs, then site-start.el will be in

c:/myPrograms/Emacs/share/emacs/site-lisp/site-start.el

Otherwise replace c:/myPrograms/Emacs with the location of Emacs on your system.

Once you open the file, search for the following lines in it:

   ;; Load ESS.
   (require 'ess-site)

Then put the following line just before the line containing ;; Load ESS:

(setq ess-directory-containing-R "c:/myPrograms")

Restart Emacs and when you press Alt-X R, the installed versions of R should be found.