[R] where does R search when source()?

Shin, Daehyok sdhyok at email.unc.edu
Sun Jul 11 04:40:27 CEST 2004


To my knowledge, it is a common practice for users to archive some script
files in other directories than current working directory, when the script
files are frequently used in many cases. So, it is somewhat surprising to me
there is no elegant solution to set up default search paths in R.

Here is my suggestion.
According to the setup of Python (http://docs.python.org/tut/node8.html),
when source() is called,

1. Search current working directory.
2. If not found, search the directories specified by the environment
variable RPATH.

I think this change will help users to manage script files more easily. What
do you think of it?

Daehyok Shin

> -----Original Message-----
> From: Liaw, Andy [mailto:andy_liaw at merck.com]
> Sent: Saturday, July 10, 2004 PM 10:07
> To: 'sdhyok at email.unc.edu'; R, Help
> Subject: RE: [R] where does R search when source()?
>
>
> Not really.  The best I can come up with is something like:
>
> runScript <- function(script, dir="", ...) source(file.path(dir, script,
> ...)
> scriptdir <- "/path/to/scripts"
>
> runScript(scriptdir, "myScript.R")
>
> Andy
>
> > From: Shin, Daehyok
> >
> > The reason I asked is to separate script files from data files.
> > Usually, I am working in the directory containing data files, but some
> > script files are in other shared directories. In the case, is
> > there any way
> > to access the script files conveniently without specifying
> > its absolute
> > path? In other word, any way to set up default search paths for script
> > files?
> >
> > Daehyok Shin (Peter)
> >
> > >
> > > The former.  No documentation says otherwise, so why would you
> > > think that it
> > > might search somewhere else?
> > >
> > > Andy
> > >
> > >
> > > ------------------------------------------------------------------
> > > ------------
> > > Notice:  This e-mail message, together with any attachments,
> > > contains information of Merck & Co., Inc. (One Merck Drive,
> > > Whitehouse Station, New Jersey, USA 08889), and/or its affiliates
> > > (which may be known outside the United States as Merck Frosst,
> > > Merck Sharp & Dohme or MSD and in Japan, as Banyu) that may be
> > > confidential, proprietary copyrighted and/or legally privileged.
> > > It is intended solely for the use of the individual or entity
> > > named on this message.  If you are not the intended recipient,
> > > and have received this message in error, please notify us
> > > immediately by reply e-mail and then delete it from your system.
> > > ------------------------------------------------------------------
> > > ------------
> > >
> >
> >
> >
>
>
> ------------------------------------------------------------------
> ------------
> Notice:  This e-mail message, together with any attachments,
> contains information of Merck & Co., Inc. (One Merck Drive,
> Whitehouse Station, New Jersey, USA 08889), and/or its affiliates
> (which may be known outside the United States as Merck Frosst,
> Merck Sharp & Dohme or MSD and in Japan, as Banyu) that may be
> confidential, proprietary copyrighted and/or legally privileged.
> It is intended solely for the use of the individual or entity
> named on this message.  If you are not the intended recipient,
> and have received this message in error, please notify us
> immediately by reply e-mail and then delete it from your system.
> ------------------------------------------------------------------
> ------------
>




More information about the R-help mailing list