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

From: Spencer Graves <spencer.graves_at_pdf.com>
Date: Sun 11 Jul 2004 - 11:13:50 EST

  In case no one who knows has time to reply to this, I will report on my empirical investigation of this question using R 1.9.1 under Windows 2000. First, I saved a simple script file "tst-source.R" in the working directory, e.g., "d:/sg/proj1". When I said, "source('tst-source.R')", it sourced the file appropriately. Then I moved this file to the immediate parent, e.g., "d:/sg" and tried the same source command. It replied, "Error ... unable to open connection ... ." Then I got a command prompt, said, "path", and moved the file into one of the directories in the search path. When I repeated the "source" command, it was still "unable to open connection ... ."

Conclusion: From this and other experiences, I have found three ways to specify file names:

(1) If the complete path and file name are supplied for an existing file, 'source' will find it.

(2) If a file is in the working directory, specifying that name will get it.

(3) If a file is in a subdirectory of the working directory, e.g., "d:/sg/proj1/sub1/tst-source.R", then specifying "source('sub1/tst-source.R')" will get it.

hope this helps. spencer graves

Shin, Daehyok wrote:

>Exactly where does R search for foo.R if I type source(“foo.R”)?
>Only from current working directory (same as getwd()), from all directories
>specified by e.g. $PATH? Thanks.
>
>Daehyok Shin
>
>______________________________________________
>R-help@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
>
>



R-help@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 Received on Sun Jul 11 11:21:07 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 02:35:28 EST