[R] Saving/loading custom R scripts

Abhijit Dasgupta, PhD adasgupta at araastat.com
Wed Sep 8 13:19:50 CEST 2010


  You can create a .First function in your .Rprofile file (which  will 
be in ~/.Rprofile). For example

.First <- function(){
     source("Friedman-Test-with-Post-Hoc.r.txt")
}

You can also create your own package ("mylibrary") down the line (see 
the R manual for creating extensions at 
http://cran.fhcrc.org/doc/manuals/R-exts.pdf) which will be a collection 
of your custom scripts that you have written, and then you can 
automatically load them using

.First <- function(){
     library("mylibrary")
}

Hope this helps.

Abhijit

On 9/8/10 3:25 AM, DrCJones wrote:
> Hi,
> How does R automatically load functions so that they are available from the
> workspace? Is it anything like Matlab - you just specify a directory path
> and it finds it?
>
> The reason I ask is because  I found a really nice script that I would like
> to use on a regular basis, and it would be nice not to have to 'copy and
> paste' it into R on every startup:
>
> http://www.r-statistics.com/wp-content/uploads/2010/02/Friedman-Test-with-Post-Hoc.r.txt
>
> This would be for Ubuntu, if that makes any difference.
>
> Cheers


-- 

Abhijit Dasgupta, PhD
Director and Principal Statistician
ARAASTAT
Ph: 301.385.3067
E: adasgupta at araastat.com
W: http://www.araastat.com



More information about the R-help mailing list