[R] directory of current script
Thomas Lumley
tlumley at uw.edu
Fri Apr 13 03:37:25 CEST 2012
On Fri, Apr 13, 2012 at 11:37 AM, pdb <philb at philbrierley.com> wrote:
> I am running a series of scripts sequentially and they all need some global
> parameters. These will be included in a file in a known sub directory as the
> scripts themselves.
>
> The scripts need to be run by anyone without ANY editing.
>
> Question is:
>
> Is there a command to return the directory of the current script, so it then
> knows where to find the global parameter file?
There isn't a completely general way to do this, because there might
not *be* a directory
source("http://bioconductor.org/biocLite.R")
source(textConnection("print('Hello, world.')"))
source("")
etc
However, source() has a chdir=TRUE option that sets the current
working directory to the directory of the file, if it is a file and
has a directory, and then getwd() will return that directory.
-thomas
--
Thomas Lumley
Professor of Biostatistics
University of Auckland
More information about the R-help
mailing list