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? Thanks in advance, Cliff -- View this message in context: http://r.789695.n4.nabble.com/Looking-up-the-directory-a-file-is-located-in-tp3047649p3047649.html Sent from the R help mailing list archive at Nabble.com.
What do you expect it to look up? How do you want to specify the directory? Is it supposed to search through some sequence or use ESP? 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? > > > Thanks in advance, > > Cliff > > > -- > View this message in context: http://r.789695.n4.nabble.com/Looking-up-the-directory-a-file-is-located-in-tp3047649p3047649.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Gabor Grothendieck
2010-Nov-18 16:06 UTC
[R] Looking up the directory a file is located in
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 at r-project.org/msg111871.html -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com