exams2pandoc(file, n = 1L, nsamp = NULL, dir = ".",
name = "pandoc", type = "docx", template = "plain.tex",
question = "Question", solution = "Solution",
header = list(Date = Sys.Date()), inputs = NULL, options = NULL,
quiet = TRUE, resolution = 100, width = 4, height = 4, svg = FALSE, encoding = "",
edir = NULL, tdir = NULL, sdir = NULL, verbose = FALSE, points = NULL, …)
file
.file
. Sampling without replacement is used
if possible. (Only if some element of nsamp
is larger than
the length of the corresponding element in file
, sampling
with replacement is used.)dir
is explicitly specified, the file is displayed in the
browser rather than saved in dir
."docx"
(but other choices are also supported, e.g., "odt"
,
"html"
, "markdown"
etc.)."plain.tex"
file provided but an alternative "plain.html"
is also available.question
is a character it will be used as a header for
resulting questions.question
.template
.template
(e.g., images, headers). Either the full path
must be given or the file needs to be in edir
.pandoc_convert
.xweave
?xweave
.xweave
.file
are stored (see also below).tempdir
. Note that this
is cleaned up and potentially temporary files are deleted.tempdir
.expoints
tags
of the exercise files (if any). The vector of points supplied should either have
length 1 or the number of exercises in the exam.exams2pandoc
returns a list of exams as generated by xexams
.exams2pandoc
can generate exams in various output formats
(by default docx) using xexams
and
pandoc_convert
. It proceeds by (1) calling
xweave
on each exercise, (2) reading the resulting
LaTeX or Markdown code, (3) transforming the code to the markup of
some exam template (either LaTeX, HTML, or Markdown), (4) embedding the
code in a template and converting it to the desired output format
using pandoc. For steps (1) and (2) the standard drivers in xexams
are used. For step (3) a suitable transformation function is set up on the fly
using make_exercise_transform_pandoc
. Depending
on which format the template uses (LaTeX or HTML or Markdown) the
transformation may or may not be trivial. For step (4) all exercises are inserted into the template (and also
replacing certain additional tags from header
) and then
pandoc_convert
is used to convert to the
desired output format (one file for each exam). In principle, all output
types of pandoc are supported, but most of them have not been tested.
(The main motivation for exams2pandoc
was the generation of
"docx"
or "odt"
files.)xexams
,
pandoc_convert
## load package and enforce par(ask = FALSE)
options(device.ask.default = FALSE)
## define an exams (= list of exercises)
myexam <- list(
"boxplots",
c("tstat", "ttest", "confint"),
c("regression", "anova"),
c("scatterplot", "boxhist"),
"relfreq"
)
## output directory
mydir <- tempdir()
## compile two docx and odt versions each
set.seed(1090)
exams2pandoc(myexam, n = 2, dir = mydir, type = "docx")
set.seed(1090)
exams2pandoc(myexam, n = 2, dir = mydir, type = "odt")
Run the code above in your browser using DataLab