I'm trying to create automated PDF RMarkdown reports for fitness testing data based on the training hub city.
I believe I'm very close by following the outline here: R Knitr PDF: Is there a posssibility to automatically save PDF reports (generated from .Rmd) through a loop?
However, this is creating reports with the same data for only 1 hub despite both being named differently (report.A.pdf and report.B.pdf). How can I get the subgroup to loop properly to show data from the different hubs?
Sample data:
Date Athlete Test Average Hub
1 2019-06-03 Athlete1 Broad_Jump 175.000000 A
2 2019-06-10 Athlete1 Broad_Jump 187.000000 A
3 2019-06-10 Athlete2 Broad_Jump 200.666667 B
4 2019-06-10 Athlete3 10m_Sprint 1.831333 B
5 2019-06-10 Athlete2 10m_Sprint 2.026667 B
6 2019-06-17 Athlete1 Broad_Jump 191.500000 A
7 2019-06-17 Athlete2 Broad_Jump 200.666667 B
8 2019-06-17 Athlete3 10m_Sprint 1.803667 B
9 2019-06-17 Athlete2 10m_Sprint 2.090000 B
10 2019-06-24 Athlete1 Broad_Jump 192.000000 A
R Script for Rendering RMarkdown
WT <- read.csv("WT.csv")
for (hub in unique(WT$Hub)){
subgroup <- subset(WT, Hub == hub)
render("Hub_Test.rmd",output_file = paste0('report.', hub, '.pdf'))
}
RMarkdown File (Hub_Test.rmd):
WT <- read.csv("WT.csv")
for (hub in unique(WT$Hub)){
subgroup <- subset(WT, Hub == hub)
}
summary(subgroup)
This set up creates 2 PDFs in my working directory with ONLY A data. I must be missing something.