Quantcast

directory of current script

classic Classic list List threaded Threaded
4 messages Options
pdb
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

directory of current script

pdb
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?

Or is there a simpler way?

Cheers.
pdb
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: directory of current script

pdb
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: directory of current script

David Winsemius
In reply to this post by pdb

On Apr 12, 2012, at 7:37 PM, pdb 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 is:

?getwd()

Whether that satisfies will depend on specifics you have not supplied.

>
> --
> View this message in context: http://r.789695.n4.nabble.com/directory-of-current-script-tp4553386p4553386.html

Great!  there is some unspecified context as well. Learn to post to  
rhelp so we don't need to access nabble.


> Sent from the R help mailing list archive at Nabble.com.

Not from the R help mailing list. From a website posing as Rhelp.

--

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: directory of current script

Thomas Lumley-2
In reply to this post by pdb
On Fri, Apr 13, 2012 at 11:37 AM, pdb <[hidden email]> 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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Loading...