Skip to content

Path to R script

3 messages · Gabor Grothendieck, Johannes W. Dietrich, Charlie Sharpsteen

#
If you are running the file via source("myfile.R") then just put this
in the file:

this.dir <- dirname(sys.frame(1)$ofile)

This is a bit fragile since changes to the internals of source could
break it but it does currently work.

On Wed, May 12, 2010 at 3:31 PM, Johannes W. Dietrich
<j.w.dietrich at medizinische-kybernetik.de> wrote:
#
At 19:29 Uhr -0400 12.05.2010, Gabor Grothendieck wrote:
Great, this is the solution. It works if the script has been saved 
before running.

Thank you,

J. W. D.
#
Johannes W. Dietrich wrote:
I *strongly* suggest you consider packages if you are sharing collections of
R functions and scripts with other people.  Compared to other programming
languages I have used, R makes it dead simple to create packages.  All you
really need to get started is:

  ?package.skeleton()

That command creates a set of folders whose structure is pretty self
explanatory:

  package.skeleton( 'myPackage' )

Creates the beginnings of a package structure:

  myPackage/
    
     R/  => Files containing your custom R functions go in here

     data/  => Data sets go in here

     man/  => For documentation files

     inst/   => Everything else such as scripts and config files

The "Writing R Extensions Manual" can help you fill in the rest of the
blanks.

The bottom line is that creating a package cost a minimal investment of
extra time and pays back huge dividends if the collection of scripts and
data files you are sharing gets complex or you people ask you to document
the software that they are starting to depend on.

-Charlie

-----
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University