[R] Managing R objects with 'make'

Thomas Lumley tlumley at u.washington.edu
Fri May 11 19:30:26 CEST 2001


On Fri, 11 May 2001, Taylor, Z Todd wrote:

> I frequently use Makefiles to manage routine data manipulations
> and repeated analyses where the "raw" data tend to change
> with time.  With S/Splus, this has worked quite naturally, as
> long as I'm careful to use S object names that map directly
> to Unix/Linux filenames.
>
> For example, say I'm building a particular graphic (chart.ps)
> from a data.frame in S (mydata) that comes from an external
> data file (mydata.csv).  The makefile snippet would look like:
>
>    chart.ps: .Data/mydata mkchart.src
>    	Splus < mkchart.src > mkchart.log 2>&1
>
>    .Data/mydata: mydata.csv build_mydata.src
>    	Splus < build_mydata.src > build_mydata.log 2>&1
>
> Of course, build_mydata.src would do a read.table on
> mydata.csv plus other necessary transformations.
>
> I'm looking for suggestions how I might achieve similar
> functionality using R.
>
> My work involves many other programs besides S, so I'm
> very reluctant to abandon the Makefile approach to use R.
> But it's not obvious to me that I can use 'make' to manage
> individual objects in R.

You *can* store individual objects or sets of objects in files in R, it
just doesn't happen automatically. If your object creation is done by
scripts it is easy to build in a save() command

Eg  build_data.r

x<-read.table("xfile.dat")
y<-read.table("yfile.dat")
z<-somefunctionof(x,y)
save(x,y,z,file="xyz.rdata")


   mkchart.R

load("xyz.rdata")
postscript("chart.ps")
plot(someobjectbasedon(x,y,z))
dev.off()


	-thomas


Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list