0

This is more of a generic question to let because I don't know where to start. I'm not a teacher, but this is the example I'll use because it's relatable. I'm using R, and Sweave to generate these reports.

Say I was a teacher with 6 classes and I wanted to generate a report for each class. Each report started with a summary table that listed each student in the class and their grade for the current period and previous periods. In the subsequent pages of each report is a one-page summary of each student for the current grading period that has some graphs and scores on homework, quizzes, tests, etc.

I've used this answerto generate loop reports to much success and can probably fumble my way through generating the summary page to begin each report; however, I'm a bit confused as to how to get the subreports for each student. Any advice as to what to search for or online articles is greatly appreciated. Also, if you have general advice for my general question, that is greatly appreciated, as well.

Community
  • 1
  • 1
Brian Balzar
  • 307
  • 1
  • 14

1 Answers1

0

For anyone that sees this, the key is to google Master and Child Sweave Documents. Here's a general answer:

classes.r

library(knitr)
library(tidyverse)

class_scores <- data.frame(class = as.factor(rep(1:5, 520)),
                       student = rep(letters, 100),
                       score = runif(2600, min = 50, max = 100))
for (i in 1:5){
  class_sub <- class_scores %>%
    filter(class == i)
  title <- paste0("class", i, ".tex")
  knit2pdf("master_class.rnw", title)
}

master_class.rnw

\documentclass{article}

\begin{document}

Here's the report for Class \Sexpr{i}

\clearpage

\section{Summary}

The Summary of the Class.
<<master_summary, include = FALSE>>=
  summary <- class_sub %>%
    group_by(student) %>%
    summarize(score = mean(score))
@

\Sexpr{kable(summary)}

\section{Student Reports}

Here's the section for each Student's report

\clearpage

<<master_loop, include = FALSE>>=

  student_out <- NULL

  for (let in letters) {
    student_out <- c(student_out, knit_child("student_report.rnw"))
  }
@

\Sexpr{paste(student_out, collapse = "\n")}

End Class Report

\end{document}

student_report.rnw

Here is the report for student \Sexpr{let}

%note: don't name these code chunks!

<<include = FALSE>>=
  student <- class_sub %>%
    filter(student == let)

  p <- ggplot(student, aes(x = score)) +
    geom_histogram()
@

\Sexpr{summary(student$score)}

<<echo = FALSE>>=
  p
@

End Student Report

\clearpage
Brian Balzar
  • 307
  • 1
  • 14