[ESS] Updating Emacs working directory after issuing an R setwd()
Stephen Eglen
S.J.Eglen at damtp.cam.ac.uk
Thu Jun 4 10:27:47 CEST 2009
Blanchette, Marco <MAB at stowers.org> wrote:
> Dear list,
>
> Is there a way to reset the emacs working directory of the ESS buffer
> after using setwd() in an R session? Could this be automated following
> a setwd() call?
I had written this a while ago:
(defun ess-change-directory (path)
"Set the current working directory to PATH for both *R* and Emacs."
(interactive "DDirectory to change to: ")
(when (file-exists-p path)
(ess-command (concat "setwd(\"" path "\")\n"))
;; use file-name-as-directory to ensure it has trailing /
(setq default-directory (file-name-as-directory path))))
If you put that in .emacs, and then within an *R* buffer, do M-x
ess-change-directory it will prompt you for a dir -- give a dir and R
and Emacs will be in sync as to what directory you want. Automatically
tracking the directory is possible, but I've never found it necessary so
have not done it.
Stephen
More information about the ESS-help
mailing list