Re: [R] setting the current working directory to the location of the source file

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sun, 13 Jun 2010 09:07:30 -0400

On Thu, Jun 10, 2010 at 8:33 PM, Marcin Gomulka <mrgomel_at_gmail.com> wrote:
> AFAIK a script run through source() does not have any legit way to learn
> about it's own location.
>
> I need this to make sure that the script will find its datafiles after I
> move the whole directory. (The datafiles are in the same directory.)
>
> Here is a hack I invented to work around it:
>
> print(getwd())
> source_pathname  = get("ofile",envir = parent.frame())
> source_dirname = dirname(source_pathname )
> setwd(source_dirname)
> print(getwd())
>

This variation is nearly the same:

https://stat.ethz.ch/pipermail/r-help/2010-May/238804.html



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. Received on Sun 13 Jun 2010 - 13:09:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 13 Jun 2010 - 13:40:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive