I'm creating a small package for generating exams with randomly ordered questions (and responses on multiple choice items) and the R part is going fine, but now I need a little more control over the resulting LaTeX that is created when rendering a .pdf.
Here is my issue: questions and their corresponding response items can be split across multiple pages, which is not ideal. I've come up with a suitable LaTeX solution by encapsulating the question items within a minipage. The original .tex file looks something like this:
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  Which bear is best?
  A. Teddy bear\\
  B. Black bear\\
  C. Grizzly bear\\
  D. Honey bear\\
  E. Polar bear
\item
  Which beer is best?
  A. Miller Lite\\
  B. Naturdays\\
  C. Leine's\\
  D. Hamm's\\
  E. PBR
\end{minipage}
And my minipage solution is to do something like this:
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\begin{minipage}{\linewidth}
\item
  Which bear is best?
  A. Teddy bear\\
  B. Black bear\\
  C. Grizzly bear\\
  D. Honey bear\\
  E. Polar bear
\end{minipage}
\begin{minipage}{\linewidth}
\item
  Which beer is best?
  A. Miller Lite\\
  B. Naturdays\\
  C. Leine's\\
  D. Hamm's\\
  E. PBR
\end{minipage}
The problem is that I don't know how to do this with RMarkdown and R in a one step process. Ideally, a user would have an .Rmd file in which they simply do something like...
---
title: Some test
output: pdf_document
---
```{r}
library(examgen)
output_questions("/path/to/questions.json")
```
and the LaTeX will be formatted appropriately, but I think this is not simply an issue of including a custom .tex file (I could be wrong here). I could easily create a shell script that inserts the minipagess at the appropriate place and then again renders a .pdf with pdflatex or whatever was being used, but obviously this is not the most user friendly. I'd also like this package to be able to output .html as well. 
I can provide more details about the R code if that's relevent.
EDIT
I've created a branch of my git repo for this question so you can see exactly what I'm dealing with:
# clone the repo for access to example .Rmd and data
git clone -b se-question https://gitlab.com/mhaffner/examgen.git
# install the package
Rscript -e "devtools::install('examgen/R')"
# render rmarkdown
Rscript -e "rmarkdown::render('examgen/examples/exam-template.Rmd')"
Then you can look at the files examples/exam-template.tex and examples/exam-template.pdf.
EDIT 2
And here's a simpler example that skirts by the package but gets to the root of the issue:
---
title: "Exam Title"
author: "Your name here"
date: "November 21, 2019"
output:
  pdf_document:
    keep_tex: true
fontsize: 12pt
geometry: margin=1in
---
```{r results = "asis", echo = FALSE}
question <- c("1. Which beer is best?\n
\tA. Miller Lite\n
\tB. Hamm's\n")
cat(question)
cat("\n")
cat(question)
cat("\n")
```
Put this is in a .Rmd, render it, and take a look at the resulting .tex and .pdf.
