[R] filename of source file

Andrew C. Ward andreww at cheque.uq.edu.au
Mon Aug 5 07:35:14 CEST 2002


If you use the chdir argument to source(), this will tell your .r file to
work in that directory (including writing output to files). For example,
if you have a file called test.r in c:/tmp that contains the commands
        my.test <- sample(1:5, 100, replace=TRUE)
        write.table(my.test, "test.out")
you can call it using
        > source("c:/temp/test.r", chdir=TRUE)
after which there will be a file in c:/temp called test.out.

Does this achieve what you want?


Regards,

Andrew C. Ward

CAPE Centre,
The University of Queensland
Brisbane Qld 4072 Australia
andreww at cheque.uq.edu.au

----- Original Message -----
From: David Richmond <daver969 at mac.com>
To: Andrew C. Ward <andreww at cheque.uq.edu.au>
Cc: <r-help at hypatia.math.ethz.ch>
Sent: Monday, August 05, 2002 3:25 PM
Subject: Re: [R] filename of source file


> Yes, source refers to the use of the source() function. Suppose I invoke
> a file like so:
>
> source("/path/name/filename.r")
>
> I want to insert a command in filename.r like so:
>
> fullpath <- magic_command()
>
> such that fullpath is now "/path/name/filename.r"
>
> In other words, I want filename.r to be able to figure out where it is,
> regardless of where I put it, so that it can save all its output in the
> same directory.
>
> dave r
>
>
> On Sunday, August 4, 2002, at 10:09 PM, Andrew C. Ward wrote:
>
> > Dave,
> >
> > You may like to give an example usage since I'm not 100% sure what you
> > wish
> > to achieve. Does "current source" refer to the source() command, to
> > read.table(),
> > or to something else?
> >
> > You may like to create a variable save.dir in your .Rprofile or in your
> > working
> > session that points to the folder you want everything saved in.
> >
> > Regards,
> >
> > Andrew C. Ward
> >
> > CAPE Centre,
> > The University of Queensland
> > Brisbane Qld 4072 Australia
> > andreww at cheque.uq.edu.au
> >
> > ----- Original Message -----
> > From: David Richmond <daver969 at mac.com>
> > To: <r-help at stat.math.ethz.ch>
> > Sent: Monday, August 05, 2002 12:31 PM
> > Subject: [R] filename of source file
> >
> >
> >> Hi
> >> Is there a command which will return the complete pathname of the
> >> file from which the current source is being read? I want something
> >> which
> >> can be inserted into any .r file and it will be able to ascertain
> >> exactly where it is, so that it can save data to the same directory, no
> >> matter where it is, regardless of what the current working directory
> >> is.
> >>
> >> Dave Richmond
> >> daver969 at mac.com
> >> ------------------------------------------------------
> >> "It works on a complex scientific principle
> >> known as pot luck." - The Doctor
> >>
>
>> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> >> -.
> > -.-.-
> >> r-help mailing list -- Read
> > http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> >> Send "info", "help", or "[un]subscribe"
> >> (in the "body", not the subject !)  To: r-help-
> >> request at stat.math.ethz.ch
> >>
>

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list