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

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Thu Jun 1 15:28:25 CEST 2017


I do this regularly with knitr [1]. I have never used odfWeave, but would imagine that similar principles apply. 

If you make a child document that assumes that the desired data are stored in one or more objects, then you can use a for loop in the master document that repeatedly extracts the desired subsets and puts them into the objects the child document expects them to be in, parses the child document, and then "cat"s the parsed results into the master document output.

[1] https://yihui.name/knitr/demo/child/
-- 
Sent from my phone. Please excuse my brevity.

On June 1, 2017 3:55:33 AM PDT, "POLWART,  Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION TRUST) via R-help" <r-help at r-project.org> wrote:
>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}}
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.



More information about the R-help mailing list