[ESS] following setwd

Stephen Eglen S.J.Eglen at damtp.cam.ac.uk
Fri Jul 15 11:22:15 CEST 2005


 > I've been trying to make the default directory that gets printed in the
 > minibuffer when, e.g., one does C-x C-f in the iESS buffer, show the value
 > of getwd(). Basically, have that default directory "follow" the calls to
 > setwd. Not that this occurs often, but on occassion I do setwd to save
 > time typing file names and need to access those files directly. Is there
 > such a feature in ESS 5.2.8? I couldn't find something like that in the
 > manual. This is with:
 > 

Good quesion, and one that has come up before.  Thomas came up with 
the following suggestion a few months ago to handle this case.

----------------------------------------------------------------------
From: Thomas Lumley <tlumley at u.washington.edu>
Sender: ess-help-bounces at stat.math.ethz.ch
To: Stephen Eglen <S.J.Eglen at damtp.cam.ac.uk>
Cc: Henrik Andersson <h.andersson at nioo.knaw.nl>, ess-help at stat.math.ethz.ch
Subject: Re: [ESS] Following setwd() to a new place
Date: Mon, 3 Jan 2005 09:05:57 -0800 (PST)

On Mon, 3 Jan 2005, Stephen Eglen wrote:

> Automatic directory syncing might be tricky, but it may not be too
> hard to get something working manually.  *shell* buffers can be kept
> in sync using M-x shell-resync-dirs.
>


A fairly simple solution would be to define an ess-change-directory 
that asks the user to specify a path to emacs and then have ESS issue the 
setwd() command. After all, that's how the initial working directory is 
set.

 	-thomas

______________________________________________
ESS-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help
----------------------------------------------------------------------

So, how about putting the following in your .emacs


(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))))


and then in an *R* buffer, to change directory, do M-x
ess-change-directory RET path RET
and then it will change both the directory in *R* and the
default-directory in Emacs.

Stephen




More information about the ESS-help mailing list