Thursday, July 31, 2014

Running R with Cocoa Emacs (ESS)

When I tried to run R in Cocoa Emacs on Mac, I encountered this error:

Searching for program: No such file or directory, R

It seems that I used to be able to run it properly.  Anyway, here is how I solved the problem after doing some search (see this page).  I just needed to add the following line to ~/.emacs:

(setq-default inferior-R-program-name "/usr/local/bin/R")

And then R could be run properly again.

Some other notes:
  • I could run R without the above line if I start Cocoa Emacs by running this command "open -a Emacs".  Probably Emacs inherits some environment variables with appropriate values.
  • I couldn't solve the problem by adding the path to R by (setenv "PATH" (concat "/usr/local/bin" ":" (getenv "PATH")))  as reported in some other posts.  I am not sure why.