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

Duncan Murdoch dmurdoch at pair.com
Sun Jul 11 19:12:31 CEST 2004

I wrote:

>I agree that this is a good use for a script, but I don't think it's
>what Daehyok was talking about. He wants a library of frequently used
>scripts to be available in multiple projects.   In R, the best way to
>do that isn't to use scripts at all, it's to put the code in

On Sun, 11 Jul 2004 12:41:20 -0400, "Shin, Daehyok"
<sdhyok at email.unc.edu> wrote:

>What I asked is the way to set up default search paths for source function,
>whether or not files in the paths contain a set of functions or simple
>script code.

Gabor gave you a way to do that.  I was responding to your suggestion
that R should be modified to make this more convenient, because

>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.

I don't think this is a common practice; if it is, it shouldn't be.
Frequently used code should be in functions.  There are a lot of ways
to get those functions into your workspace, but R packages are the
best one.  There *is* a mechanism (the .libPaths function) for
specifying a search path for packages.

Duncan Murdoch

More information about the R-help mailing list