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

Gabor Grothendieck ggrothendieck at gmail.com
Thu Nov 18 17:06:06 CET 2010


On Wed, Nov 17, 2010 at 4:08 PM, Cliff Clive <cliffclive at gmail.com> wrote:
>
> Hello everyone,
>
> This should be an easy question, I think.
>
> I'd like to write a command in a program to set the working directory to
> whatever directory the file is currently stored in.  Suppose I have a file
> called "myRscript.r", and it's stored in "C:\Rprojects\myRscript.r", and it
> references other R scripts and data files in the same directory.
>
> If I enter the command
>
>> setwd("C:/Rprojects")
>
> I can then access all the files I need without typing the path.
>
> But suppose I want to move all of those files into another folder, say,
> "C:\NewFolder".  And suppose I might do this fairly often, or make copies of
> the script in several folders.  Is there a command that looks something like
> this:
>
>> setwd( <look up current directory> )
>
> that will work no matter where I move my project, without having to go in
> and re-type the new directory path?

For two solutions see:

https://stat.ethz.ch/pipermail/r-help/2005-November/082347.html

http://www.mail-archive.com/r-help@r-project.org/msg111871.html



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list