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

2010-06-13 Thread Gabor Grothendieck
On Thu, Jun 10, 2010 at 8:33 PM, Marcin Gomulka 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 direc

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

2010-06-13 Thread Marcin Gomulka
On Fri, Jun 11, 2010 at 11:30 AM, Henrik Bengtsson wrote: > Isn't this what source(..., chdir=TRUE) is for? See help(source). > > not really. Imagine you give someone a script, but you have no control over where and how they run it. They shouldn't be required to put in the chdir parameter. Say,

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

2010-06-13 Thread Marcin Gomulka
Charles' hint was what I was looking for. Thanks! mg. On Fri, Jun 11, 2010 at 7:40 AM, Charles C. Berry wrote: > > > cat("print(eval(sys.calls()[[1]][[2]]))",file='test.R') >> > >> >> > See > >?sys.calls > > [[alternative HTML version deleted]] __

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

2010-06-11 Thread Henrik Bengtsson
Isn't this what source(..., chdir=TRUE) is for? See help(source). /H On Fri, Jun 11, 2010 at 2:33 AM, Marcin Gomulka 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

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

2010-06-10 Thread Charles C. Berry
On Fri, 11 Jun 2010, Marcin Gomulka wrote: AFAIK a script run through source() does not have any legit way to learn about it's own location. You mean like 'test.R' being able to figure out that that is what it is called when it is invoked from source()? cat("print(eval(sys.calls()[[1]][[

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

2010-06-10 Thread Mohan L
On Fri, Jun 11, 2010 at 6:03 AM, Marcin Gomulka 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 dire

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

2010-06-10 Thread Marcin Gomulka
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