Re: [R] using self-written functions

From: Christophe Pallier <christophe_at_pallier.org>
Date: Thu, 28 Jun 2007 13:23:33 +0200

One "quick and dirty" way is to put all your functions inside a file, say /home/me/R/myfuncs.R, and add the following line at the beginning of your scripts:

source('/home/me/R/myfuncs.R')

This is dirty because if you need to change the location of this file, your scripts will cease to work.
Alternatively, you can add this command to your Rprofile (see the Annex B of An introduction to R "Invoking R")

Christophe

On 6/28/07, R. Leenders <suffenaam_at_yahoo.com> wrote:
>
> Hi, I am pretty new to R, so I apologize for the obvious question.
> I
> have worked with R for a few months now and in the process have written
> several functions that I frequently use in various data analysis
> projects. I tend to give each project a directory of its own and set
> the working directory to that.
> Since there are several tasks that
> need to be accomplished in many of my projects, I frequently want to
> use functions I have written previously. My question is, how do I get
> access to them? The way I do it now is copy the relevant code to the
> script file of the project I am working on at the time and then run it
> so as to make the functions available. But that seems to be
> unnecessarily cumbersome. I used to work a lot with gauss, which had
> the opportunity of putting one's own functions is one directory and
> gauss would then have that directory in its search path always. How can
> I access my own functions in R without having to copy-paste them
> everytime and run them manually so I can call them later? Do I need to
> learn how to write a package and attach the package to make the
> functions available at all times? Is there another way?
>
> thanks, James
>
>
>
>
>
>
> ____________________________________________________________________________________
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch 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.
>

-- 
Christophe Pallier (http://www.pallier.org)

	[[alternative HTML version deleted]]

______________________________________________
R-help_at_stat.math.ethz.ch 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.
Received on Thu 28 Jun 2007 - 11:59:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 28 Jun 2007 - 12:32:39 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.