[R] Looking up the directory a file is located in

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Thu Nov 18 09:00:05 CET 2010

On Thu, Nov 18, 2010 at 12:00 AM, Cliff Clive <cliffclive at gmail.com> wrote:
> Basically I'm just looking for a command that can look up the name of the
> directory of the script that is running.  If I move or copy the script to
> another directory, it should be able to read the name of the new directory
> without me having to edit the code.
> Once I have identified the directory, I can insert it into the setwd()
> command and continue with my program.

 This is a fairly-frequently asked question, and the questioner is
rarely satisfied with the answer.

 How is your script starting? Either:

 a) R is starting in that directory, so that the working directory is
already set, or

 b) Whatever runs the script knows where it is in order to start it,
so could pass that directory to the script somehow, either by a global
parameter, or an environment variable.

More information about the R-help mailing list