Our solution for - let's say - 5 different versions:
Prepare your own intro with randomly generated data (i.e. Intro.Rmd
). Our Intro.Rmd
also saves the generated data frames in a folder named Databases
. Which is then called by each exercise of the correspondent loop (i
).
When rendering rmd files to pdf you must call the right LaTeX packages in your rmd's yaml header. Our case:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{threeparttablex}
- \usepackage[normalem]{ulem}
- \usepackage{makecell}
- \usepackage{xcolor}
Several folders were created:
- one for the generated Intros (i.e.,
Intros
);
- one for the exams2nops generated PDFs (i.e.,
nops_pdf
);
- one for the spitted files (i.e.,
subsets
);
- one for the final merged versions (i.e.,
exams
).
The loop:
for (i in 1:5) {
rmarkdown::render(input = "Intro.Rmd",output_file = paste0("Intros/Intro_v",i,".pdf"))
exams2nops(questions, n = 1, nsamp = 1, intro = "Leia as questões com atenção e MARQUE TODAS AS SUAS RESPOSTAS NA FOLHA DE RESPOSTAS! Este exame tem a duração de 60 minutos. Boa sorte!", language = "pt-PT", institution = "Análise Estatística II", title = "Época Normal: Métodos Tipo I - ",dir = "nops_pdf", name = paste0("Ex_AEII_MTI_v",i,"_"), date = "2020-12-01",encoding = "UTF-8", blank = 0, nchoice = 5, duplex = T, reglength = 7L, points = 4, replacement = T,schoice = list(eval = ee))
pdf_subset(input = paste0("nops_pdf/Ex_AEII_MTI_v",i,"_1.pdf"),pages = c(1,3),
output = paste0("subsets/subset_",i,"_part1.pdf"))
pdf_subset(input = paste0("nops_pdf/Ex_AEII_MTI_v",i,"_1.pdf"),pages = c(5:pdf_length(paste0("nops_pdf/Ex_AEII_MTI_v",i,"_1.pdf"))),
output = paste0("subsets/subset_",i,"_part2.pdf"))
pdf_combine(input = c(paste0("subsets/subset_",i,"_part1.pdf"),
paste0("Intros/Intro_v",i,".pdf"),
paste0("subsets/subset_",i,"_part2.pdf")),
output = paste0("exams/exams_v",i,".pdf"))
}
Achim, you say that the pdf generated by the Intro.Rmd
can be merged using exams2nops
, can you exemplify how?