[R] odfWeave - A loop of the "same" data

POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION TRUST) calum.polwart at nhs.net
Thu Jun 1 12:55:33 CEST 2017


Before I go and do this another way - can I check if anyone has a way of looping through data in odfWeave (or possibly sweave) to do a repeating analysis on subsets of data?

For simplicity lets use mtcars dataset in R to explain.  Dataset looks like this:

> mtcars
               mpg cyl disp  hp drat   wt ...
Mazda RX4     21.0   6  160 110 3.90 2.62 ...
Mazda RX4 Wag 21.0   6  160 110 3.90 2.88 ...
Datsun 710    22.8   4  108  93 3.85 2.32 ...
               ............

Say I wanted to have a 'catalogue' style report from mtcars, where on each page I would perhaps have the Rowname as a heading and then plot a graph of mpg highlighting that specific car

Then add a page break and *do the same for the next car*.  I can manually do this of course, but it is effectively a loop something like this:

for (n in length(mtcars$mpg)) {
barplot (mtcars$mpg, col=c(rep(1,n-1),2,rep(1,length(mtcars$mpg)-n)))
}

There is a odfWeave page break function so I can do that sort of thing (I think).  But I don't think I can output more than one image can I?  In reality I will want several images and a table per "catalogue" page.

At the moment I think I need to create a master odt document, and create individual catalogue pages.  And merge them into one document - but that feels clunky (unless I can script the merge!)

Anyone got a better way?




********************************************************************************************************************

This message may contain confidential information. If yo...{{dropped:21}}



More information about the R-help mailing list