Using this link: http://www.reed.edu/data-at-reed/software/R/markdown_multiple_reports.html
I managed to write the R script and the RMarkdown Files that enable multiple PDF files to be made.
I did also have to download the Latex Reader mactex as per the instructions here:
http://www.reed.edu/data-at-reed/software/R/r_studio.html
https://tug.org/mactex/mactex-download.html
Then I had to install, turn off R-Studio and turn it back on again.
It worked well.
To make it work requires an R script with the loop in it.
The loop calls the a Rmarkdown file which writes the PDF.
Here is some of the code:
R-File: --- START ---
setwd("/Users/paulbrennan/Dropbox/Teaching/SSC/Admin/")
library(knitr)
library(readxl)
data <- read_excel("results-for-year-3-ssc-as-2016-07-12-1525.xlsx")
# for each student number in the dataframe create a report
# these reports are saved in output_dir with the name specified by output_file
for (x in 1:3){
#for pdf reports
rmarkdown::render(input = "/Users/paulbrennan/Dropbox/Teaching/SSC/Admin/SSCYr3ReportsfromExcel_5.Rmd",
output_format = "pdf_document",
output_file = paste(data[x,3], "_Year3_SSC_Feedback", ".pdf", sep=''),
output_dir = "/Users/paulbrennan/Dropbox/Teaching/SSC/Admin/")
}
R File: --- END ---
Rmd File: --- START ---
---
title: "Year 3 SSC Feedback Report"
output: pdf_document
---
```{r, include=FALSE, echo=FALSE}
# create reports on students from an Excel spreadsheet.
library(readxl)
library(knitr)
library(pander)
setwd("/Users/paulbrennan/Dropbox/Teaching/SSC/Admin/")
# read in the excel file
data <- read_excel("results-for-year-3-ssc-as-2016-07-12-1525.xlsx")
n <- data[x,2]
res <- data[x,4]
```
## STUDENT ID NUMBER: `r n`
## OVERALL RESULT: `r res`
## Content
```{r, echo=FALSE, results='asis'}
names <- c("Content", "Research", "Grammar", "Style & presentation",
"Comprehension")
output <- as.character(data[x,6:10])
output2.df <- cbind(names, output)
colnames(output2.df) <- c("Content Domain", "Performance Zone")
pander(output2.df)
## Strengths
```{r, echo=FALSE, results='asis'}
cat(data[x,17])
```
Rmd File: --- END ---
N.B. The output is all black and white which is a bit boring but hey...
Also I would like to add a logo but I can't position it very well.
I may have to used Latex or some such:
http://stackoverflow.com/questions/16626462/figure-position-in-markdown-when-converting-to-pdf-with-knitr-and-pandoc
more info here:
http://galahad.well.ox.ac.uk/repro/