[R] Loading user defined functions autometically each time I start R

Patrick Connolly p_connolly at slingshot.co.nz
Thu Feb 28 20:22:32 CET 2008


On Wed, 27-Feb-2008 at 10:06AM +0000, Richard.Cotton at hsl.gov.uk wrote:

|> > I wrote some user defined function for my own. Now I want to get a 
|> mechanism
|> > so that every time I start R, those function will automatically be 
|> loaded in
|> > R without manually copying pasting. Can gurus here pls tell me how to do
|> > that? Or I have to build my own packages bundled with those functions.
|> 
|> These instructions are for Windows, there may be a slight difference on 
|> other platforms.
|> 
|> In R_HOME\etc you should have a file named RProfile.site.
|> 
|> Inside this file, you can define a .First function, which sources your 
|> functions, e.g.
|> 
|> .First <- function()
|> {
|>     source("c://myfunction.r")
|> }

Those functions will end up in each working directory you use.  Unless
you have only a small number of those functions, that will produce a
lot of unnecessary duplication.  You can avoid that by saving those
functions in a .RData type file, and then something like:

attach("/path/to/file/.RData")

There's no need for a .First file.  Having that line in your .Rprofile
will be sufficient.

It would be tidier to make them into a package, but the above will
work easily enough.

HTH

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___    Patrick Connolly   
 {~._.~}          		 Great minds discuss ideas    
 _( Y )_  	  	        Middle minds discuss events 
(:_~*~_:) 	       		 Small minds discuss people  
 (_)-(_)  	                           ..... Anon
	  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.



More information about the R-help mailing list