0

Hi I'm having trouble finding an answer / solution to what seems like a very logical problem.

Intention - I have a data frame for which I would like to produce a report for each row - ideally with the output contained in a single html or PDF.

Example Data & Code - Given a dataframe something like;

df <- data.frame(rowID=c(1:3),
                 title=c("title1","title2","title3"),
                 text=c("Lorem ipsum dolor sit amet, consectetur adipiscing elit.","Nulla facilisi. Sed eleifend eros at sollicitudin porttitor.","Nam sollicitudin, metus eget convallis efficitur, odio purus elementum ipsum")
                )

And a markdown template (template.Rmd) like this;

    ---
    #title: ""
    output: html_fragment
    params:
      storyID: blank
      titleText: blank
      bodyText: blank
    ---
    **ID**: `r params$storyID`  
    **Title:** `r params$titleText`
    `r params$bodyText`

And a little R to bind these together;

 l_ply(1:nrow(df), function(i) {
    rmarkdown::render("template.Rmd",
                      output_file =  paste("report_", i, ".html", sep=''), 
                      params = list(
                        storyID         = i,
                        titleText       = df$title[i],
                        bodyText        = df$text[i],
                        ))
  })

Where I Am At - So far with this I can happily create an html_fragment for each row resulting in dozens of files. These I could reload in R and using something like pandoc (where is available for R3.2.2) recombine into a single document but that seems a very inelegant solution.

Desired Output - Ideally I want to understand if R Markdown can create something more like a binder of reports natively. Notebooks in R Studio sounds like it might be the way but I can't find anything useful there in.
So the ideal output would be a single HTML file with each / all of those fragments combined.

Can anyone shed light here?

BarneyC
  • 529
  • 4
  • 17
  • 1
    I think you're looking for knit_child: http://yihui.name/knitr/demo/child/ – Ruben Jun 13 '16 at 08:27
  • Since found that binding RMarkdown docs together is super simple following... http://stackoverflow.com/questions/25824795/how-to-combine-two-rmarkdown-rmd-files-into-a-single-output – BarneyC Jun 13 '16 at 09:23

0 Answers0