[R] source problem
jahaye at wm.edu
Mon Jan 12 18:01:14 CET 2004
Thanks for the quick response!
That's essentially how I was expecting to have to do it in the worst
case. However, I was thinking that setting the chdir = TRUE should have
taken care of this for me. Is this a bug? Or am I using it
incorrectly? It seems like we shouldn't have to pass the paths around
On Mon, 2004-01-12 at 11:39, Simon Fear wrote:
> I would sidestep the issue by using explicit paths at all times
> but keeping the directory roots in variables; e.g.
> firstPath <- "/usr/local/algo/R/script/f"
> secondPath <- "/home/john/R_script/"
> and then you can call things like
> source(paste(firstpath, "firstScript.r", sep="")
> This scheme does require the pathnames to be set when called.
> If you wanted your second script to run stand-alone you would
> have to put in a test such as
> if (!exists(secondPath)) secondPath <- "/home/john/R_script/"
> but I find it easier to define such things in .first or
> some other file I *always* source before working on the
> project. (Actually I create a list of them, which I call global.pathnames.)
> > -----Original Message-----
> > From: John Hayes [mailto:jahaye at wm.edu]
> > Sent: 12 January 2004 16:25
> > To: r-help at stat.math.ethz.ch
> > Subject: [R] source problem
> > Security Warning:
> > If you are not sure an attachment is safe to open please contact
> > Andy on x234. There are 0 attachments with this message.
> > ________________________________________________________________
> > Hi,
> > I'm trying to call an R script from the command-line ("firstScript.r"
> > below). This script then sources another script in another directory
> > using the absolute path to the file
> > ("/home/john/R_script/secondScript.r"). That script then needs to
> > source an R script in the same directory using a relative path
> > ("thirdScript.r"). Neither script should know that it is being
> > sourced. For example,
> > /usr/local/algo/R/script/firstScript.r
> > /home/john/R_script/secondScript.r
> > /home/john/R_script/thirdScript.r
> > However, I am getting a message that this last file cannot be found.
> > I've changed the chdir and local attributes of source to TRUE and this
> > does not seem to change the behavior. Is there a way to do
> > this without
> > passing the absolute path to the R files around? Thanks for any help
> > you can offer.
> > John
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> Simon Fear
> Senior Statistician
> Syne qua non Ltd
> Tel: +44 (0) 1379 644449
> Fax: +44 (0) 1379 644445
> email: Simon.Fear at synequanon.com
> web: http://www.synequanon.com
> Number of attachments included with this message: 0
> This message (and any associated files) is confidential and
> contains information which may be legally privileged. It is
> intended for the stated addressee(s) only. Access to this
> email by anyone else is unauthorised. If you are not the
> intended addressee, any action taken (or not taken) in
> reliance on it, or any disclosure or copying of the contents of
> it is unauthorised and unlawful. If you are not the addressee,
> please inform the sender immediately and delete the email
> from your system.
> This message and any associated attachments have been
> checked for viruses using an internationally recognised virus
> detection process. However, Internet communications cannot
> be guaranteed to be secure or error-free as information could
> be intercepted, corrupted, lost, destroyed, arrive late or
> incomplete. Therefore, we do not accept responsibility for any
> errors or omissions that are present in this message, or any
> attachment, that have arisen as a result of e-mail transmission.
> If verification is required, please request a hard-copy version.
> Any views or opinions presented are solely those of the author
> and do not necessarily represent those of Syne qua non.
More information about the R-help