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 -- View this message in context: http://r.789695.n4.nabble.com/Saving-loading-custom-R-scripts-tp2530924p2530924.html Sent from the R help mailing list archive at Nabble.com.
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
Hi,
Just create a file called .Rprofile that is located in your working
directory (this means you could actually have different ones in each
working directory). In that file, you can put in code just like any
other code that would be source()d in. For instance, all my .Rprofile
files start with:
r <- getOption("repos")
r["CRAN"] <- "http://cran.stat.ucla.edu"
options(repos = r)
rm(r)
So that I do not have to pick my CRAN mirror. Similarly you could
merely add this line to the file:
source(file =
"http://www.r-statistics.com/wp-content/uploads/2010/02/Friedman-Test-with-Post-Hoc.r.txt")
and R would go online, download that file and source it in (not that I
am recommending re-downloading every time you start R). Then whatever
names they used to define the functions, would be in your workspace.
Note that in general, you will not get any output alerting you that it
has worked; however, if you type ls() you should see those functions'
names.
Cheers,
Josh
On Wed, Sep 8, 2010 at 12:25 AM, DrCJones <matthias.goddard at gmail.com>
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
> --
> View this message in context:
http://r.789695.n4.nabble.com/Saving-loading-custom-R-scripts-tp2530924p2530924.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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.
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/
One comment on the function: I see that it uses T/F instead of TRUE/FALSE in a number of places. You'll save yourself some headaches if you replace those 'T/F's. -Peter Ehlers On 2010-09-08 1:25, 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