[R] How to create something between a script and a package

Vladimir Eremeev
Tue, 09 Oct 2007 07:49:06 -0000

Sergio Correia wrote:
>
> (Before starting: I'm a total R noob so please bear with me in case of
> any error or faux pas).
>
> Hi,
>
> For a small project, I'm writing a few simple R functions and calling
> them from python (using RPy). I'm sharing the code with a couple of
> friends, using a subversion server.
>
> Now, I want something like a package, to be able to share functions
> between ourselves. Having read a few package tutorials, I feel that
> this is not exactly what I want and I'm kinda lost regarding what
> alternatives are available.
>
> What I want could be summarized as this:
> - A plain text file (eg: myfunctions.R)
> - Can be located in other folders besides the default (easier to
> synchronize using subversion). Eg: myproject/rfunctions/myfunctions.R
> - Can be accessed from the R console (without having to load a
> specific workspace).
>
> Is there any solution that can provide this?
>
> Any suggestions would be greatly appreciated,
>
> Thanks,
> Sergio
>
>

And what holds you from doing the steps you described?
Create a plain text file with functions (myfunctions.R, as you want), define
its location (myproject/rfunctions/ ) and save it there.

Then add
source("myproject/rfunctions/myfunctions.R")
early in every R script or project using those functions.

Another variant - you can save the functions with save() in
myfunctions.RData file.
If you will use save(<...>, ascii=TRUE) this file will not be binary, but
it
still will have an internal R format, and you won't be able to edit it.

Then
attach("myproject/rfunctions/myfunctions.RData")

You can add calls to source() or attach in the .Rprofile file in your local
directory or in Rprofile.site for system wide use, and your functions will
appear in R's worspace automatically. Consult with ?Startup for more
details.

--
View this message in context:
http://www.nabble.com/How-to-create-something-between-a-script-and-a-package-tf4591705.html#a13110988
Sent from the R help mailing list archive at Nabble.com.