AutomaticGenerationofExamsinR
BettinaGr
¨
un
JohannesKepler
Universit
¨
atLinz
AchimZeileis
Universit
¨
atInnsbruck
Abstract
This first t introduction n to the R package exams s is s a (slightly) modified version of
Gr
¨
un andZeileis (2009), publishedin the Journalof Statistical Software. . It t describes
howtoproducePDFfiles fromexercisesinSweaveformat. . Meanwhile,examshasbeen
considerablyextendedbyZeileis,Umlauf,andLeisch(2014)andbeyondtoalsoproduce
HTMLoutputore-learningexamsforMoodle,OLAT/OpenOLAT,etc.Thishasresulted
insomesmallchangesthatarenotfullybackward-compatibleandwhicharemarkedwith
“UPDATE”inthetextbelow.
Packageexamsprovidesaframeworkforautomaticgenerationofstandardizedstatis-
ticalexams whichis especially usefulfor large-scaleexams. . Toemploythetools, , users
justneedtosupplyapoolofexercisesandamasterfilecontrollingthelayoutofthefinal
PDFdocument. TheexercisesarespecifiedinseparateSweavefiles(containingRcode
fordatagenerationandL
A
T
E
Xcodeforproblemandsolutiondescription)andthemaster
file is aL
A
T
E
Xdocument withsomeadditionalcontrolcommands. . This s papergives an
overviewofthemaindesignaimsandprinciplesaswellasstrategiesforadaptationand
extension.Hands-onillustrations–basedonexampleexercisesandcontrolfilesprovided
inthepackage–arepresentedtogetnewusersstartedeasily.
Keywords:exams,multiplechoice,arithmeticproblems,Sweave,L
A
T
E
X,R.
1. Introduction
The introductory statistics lecture at t the e Wirtschaftsuniversit
¨
at Wien n (WU Wien, http:
//www.wu.ac.at/)isattendedeachsemesterbyabout1,000–1,500students(mostlyfirst-year
businessstudents).SeverallecturersfromtheDepartmentofStatisticsandMathematicsteach
thiscourseinparallel.Inordertoensureanefficient,consistent,andtransparentorganization,
thecourseformatandallitsteachingmaterials(presentationslides,collectionsofexercises,
exams, etc.) ) werere-designedinacollaborativeeffort t during2006/7. . Amongmany y other
aspects–suchasspecificationofatopiclistordefinitionoflearningoutcomes,etc.–thisre-
designencompassedseveraltechnologicalchallenges. Hence,theexamspackagewasdesigned
toaddressthesechallenges andthusfacilitatethediscussionsaboutthecontentofthenew
course.Morespecifically,examsaimstoprovidesoftwareinfrastructurefor:
Scalableexams: Automaticgenerationofalargenumberofdifferentexamsinorderto
provideanindividualtesttoeachstudent.
Associated self-study materials: : Collections s ofexercises andsolutions fromthesame
poolofexamples.
Convert pdf to web page online - Convert PDF to html files in C#.net, ASP.NET MVC, WinForms, WPF application
How to Convert PDF to HTML Webpage with C# PDF Conversion SDK
convert pdf to html5 open source; convert pdf to html code
Convert pdf to web page online - VB.NET PDF Convert to HTML SDK: Convert PDF to html files in vb.net, ASP.NET MVC, WinForms, WPF application
PDF to HTML Webpage Converter SDK for VB.NET PDF to HTML Conversion
convert pdf to url link; pdf to html conversion
2
AutomaticGenerationofExamsinR
Joint development: : Development t and d maintenance of f a a large e pool l of exercises in a
multi-authorandcross-platformsetting.
Specifically,atWUWienabout10–15lecturerswereworkinginsmallteamsof2–4peopleon
differentchaptersforthepresentationslides. Foreachchapter,thecorrespondingteamwould
alsoprovide suitableexercise templates thatcouldbe usedfor self-studymaterials,exams,
andsolutions.
The pool of f exercises does not t only need d to contain different t types s of f exercises, but t also
variants ofthesametypetoavoidthat studentslearnthesolutions“byheart”. . Correction
shouldbefastandeasy. This s restrictsthesuitabletypesofexercisestothosewhicheither
have a single number r as s result t whichonly y needs s to o be checked to assess the correctness,
multiple-choice questions, or potentially questions which require only ashort text answer.
Theserequirementsonmaintenance,variation,andcorrectionofexercisesledtothefollowing
designprinciplesforpackageexams:
Maintenance: Eachexercisetemplateisasinglefile(alsojustcalled“exercise”).
Variation: Exercisesaredynamicdocuments,containingaproblem/solutionalongwith
adata-generatingprocess(DGP)sothatrandomsamplescanbedrawneasily.
Correction: Solutionsforexercisesareeithermultiple-choiceanswers(logicalvectors),
numericvalues(e.g.,ateststatisticoraconfidenceinterval),shorttextanswers(e.g.,
theappropriatenullhypothesiscorrespondingtoagivenproblem),orcombinationsof
these.
Thus,theDGPofanexercisecontrolsthedistributionofpossiblesolutionsandcanbeutilized
tomakethem(approximately)evenlydistributedanddifficultto“guess”or“learnbyheart”.
Inadditiontothevariabilitywithinanexercise,onecanaddfurthervariationbyproviding
severalexercisetemplatesforthesametypeofproblem. Dependingontheflexibilityofthe
DGP,thepoolofexercisescanthusberathersmallorneedstobesomewhatlarger.
Mixingproblems/solutionsandDGPsforexamgenerationposeschallengesthataresimilar
tothoseofmakingdataanalysisreproducible.Thus,examsemploysmanyideasfromliterate
dataanalysis(Rossini2001;LeischandRossini2003),literateprogramming(Knuth1992)and
reproducibleresearch(deLeeuw2001). Specifically,itmakesextensiveuseofSweave(Leisch
2002) formixing DGPs writtenin n the Rsystemforstatisticalcomputing(RDevelopment
CoreTeam2008)andproblem/solutiondescriptionswritteninthetypesettingsystemLAT
E
X
(Knuth1984;Lamport1994).Thus,theimplementationinexamsisbasedon(1)independent
SweavefilesforeachexerciseinterweavingRandLAT
E
Xcode,(2)differentmasterLAT
E
Xfiles
controllingtheappearanceand(3)animplementationofaminimalmarkupforcommunication
withRplusRfunctionstyingeverythingtogether.
ThepackageexamsthatemergedfromthedevelopmentsatWUWienisavailablefromthe
ComprehensiveRArchiveNetworkathttp://CRAN.R-project.org/package=exams.Touti-
lizeitforexamgeneration,usersneedtogenerateapoolofexercisesandsupplyamaster
L
A
T
E
Xfile. Thepackage e provides severalexamples for bothtypes of files along withdocu-
mentation(like this paper) andhands-onexamples toget newusers started.
1
Hence, the
1
Inversion2oftheexamspackageanewfunctionexams_skeleton()hasbeenaddedtofacilitatestarting
newexamsprojects. SeeSection2.3ofZeileisetal.(2014)orvignette("exams2", package = = "exams")for
moredetails.
XDoc.HTML5 Viewer for .NET, Zero Footprint AJAX Document Image
View, Convert, Edit, Sign Documents and Images. Wide range of web browsers support including IE9+ powerful & profession imaging controls, PDF document, image to
embed pdf into html; convert pdf to html email
DocImage SDK for .NET: Web Document Image Viewer Online Demo
Document Viewer Demo to View, Annotate, Convert and Print upload a file to display in web viewer Suppported files are Word, Excel, PowerPoint, PDF, Tiff, Dicom
converting pdf to html format; convert pdf form to html
BettinaGr
¨
un,AchimZeileis
3
remainderofthispaperisorganizedasfollows:Section2explainsthestructureoftheSweave
filesdefiningtheexercisesanddemonstrateshowthefinaloutputfileisderivedfromtheorig-
inalRandL
A
T
E
Xcode. InSection3,thestructureofthemasterL
A
T
E
Xfileforconstructing
thefinalPDFfilefromtheexercisefilesispresented. FinallySection4illustrateshowtouse
thepackageinpracticeandhowexamscanbecustomized.Experiencewiththedevelopment
ofexercisesandtheapplicationofthepackagearediscussedinSection5. Section6concludes
thepaperwithasummary.
2. Exercises
Eachexerciseis containedina separateSweave fileandtypicallyrepresents an n exemplary
application of a a statistical l procedure. . It t needs to o contain (1) a a question n and a a solution
descriptionwhichareencapsulatedinL
A
T
E
Xenvironmentsofthecorrespondingnames and
(2) somemeta-information n abouttheexercisesuchastypeandthesolution. . Toallow w for
variability,thedatafortheexercisecanbegeneratedwithintheSweavefileinacodechunk
(typicallysuppressedinthefinaldocument).Meta-informationfortheexamplesneedstobe
provided,e.g.,forcomputingwiththesolutionwithinRorforgeneratinglistswithsolutions.
InTable1,theSweavefileforasimpleexerciseaskingstudentstocomputeaone-samplettest
statistic is shownfor illustration. . The e four different blocks (R code withDGP,question
environment, solution environment, meta-information) canbe easily y distinguished. . The
LAT
E
XfilegeneratedfromacalltoSweave()isshowninTable2,andthefinalcompiledPDF
outputisprovidedinTable3.
TheRcodefortheDGPisusedasinanyotherSweavedocument: Thecodechunkisframed
by<<>>=and@andoptionsintheheadercontrolformatting(typicallysuppressingthedisplay
inthefinaldocument,asinthisexample). Forfurtherinformationabouttheapplicationof
SweaveandadetaileddescriptionofthedifferentoptionsseeLeisch(2012a,b).
Thecoreofanexercisearetwoblocksforthequestionandthesolutionintheiraccordingly
namedenvironments.ThevaluesgeneratedbytheDGParetypicallyincludedusing\Sexpr{}
statements. Furthermore,question/solutionmightcontaingraphicsand/orRoutputcreated
bySweave. ToincludetheLAT
E
Xoutput(seeTable2)insomemasterLAT
E
Xfile,thisneeds
todefinethequestionandsolutionenvironment. Thismechanismcanbeusedtocontrol
thedisplay,e.g.,tosuppressthesolutioninanexambuttodisplayitinassociatedself-study
material(seeSection3forfurtherdetails).
Finally,somemeta-informationneedstobe provided. . Allmeta-informationcommands s are
inL
A
T
E
Xstylebutareactuallycommentedoutandhiddeninthefinaloutputfile. Thereare
fourcommands
2
:
\extype{}: typeofquestion. Itmaybeeithermchoicefor r multiple-choicequestions,
num for r questions s with h a numeric result t or string g for questions with a(short) text
answer.
\exsolution{}: solution. Itcontainsthenumericsolution,astringofzerosandones
formultiple-choicequestionsoracharacterstring. Forconfidenceintervals,itmayalso
specifytwonumericsolutionsoftype\exsolution{lower}{upper}.
2
Notethatversion2providesmanyadditionalcommands,especiallyfore-learningoutputandothercustom
interfaces.
C# PDF: How to Create PDF Document Viewer in C#.NET with
Support rendering web viewer PDF document to images or svg file; Free to convert viewing PDF document to TIFF file for document management;
how to convert pdf to html code; convert pdf to webpage
C# HTML5 Viewer: Load, View, Convert, Annotate and Edit PDF
such as convert PDF to Microsoft Office Word (.docx) online, convert PDF to multi PDF Annotation. HTML5 Viewer for C# .NET is an advanced web viewer of rich
best website to convert pdf to word online; pdf to html
4
AutomaticGenerationofExamsinR
<<echo=FALSE, results=hide>>=
## DATA GENERATION
n <- sample(120:250, 1)
mu <- - sample(c(125, , 200, , 250, 500, , 1000), 1)
y <- rnorm(n, , mean n = mu * runif(1, min = 0.9, , max x = 1.1),
sd = = mu * runif(1, , min n = 0.02, max x = = 0.06))
## QUESTION/ANSWER GENERATION
Mean <- round(mean(y), digits s = = 1)
Var <- round(var(y), digits = = 2)
tstat <- round((Mean n - mu)/sqrt(Var/n), digits = 3)
@
\begin{question}
A machine fills milk into $\Sexpr{mu}$ml packages. . It is s suspected d that t the
machine is not working correctly y and d that the e amount t of milk filled differs
from the e setpoint t $\mu_0 0 = = \Sexpr{mu}$. A sample of $\Sexpr{n}$ packages
filled by the e machine are e collected. The sample mean $\bar{y}$ is equal to
$\Sexpr{Mean}$ and the sample e variance e $s^2_{n-1}$ $ is equal l to
$\Sexpr{Var}$.
Test the e hypothesis s that t the e amount filled d corresponds s on average to the
setpoint. What is the e absolute e value of the $t$~test statistic?
\end{question}
\begin{solution}
The $t$~test statistic is calculated by:
\begin{eqnarray*}
t & & = = & \frac{\bar y - - \mu_0}{\sqrt{\frac{s^2_{n-1}}{n}}}
= \frac{\Sexpr{Mean} - - \Sexpr{mu}}{\sqrt{\frac{\Sexpr{Var}}{\Sexpr{n}}}}
= \Sexpr{tstat}.
\end{eqnarray*}
The absolute value of f the e $t$~test statistic is thus equal l to
$\Sexpr{fmt(abs(tstat), 3)}$.
\end{solution}
%% META-INFORMATION
%% \extype{num}
%% \exsolution{\Sexpr{fmt(abs(tstat), , 3)}}
%% \exname{t statistic}
%% \extol{0.01}
Table1: AsimpleSweaveexercise:tstat.Rnw.
XDoc.HTML5 Viewer, Create Web Doc & Image Viewer in C#.NET
pages, VB.NET comment annotate PDF, VB.NET delete PDF pages, VB.NET convert PDF to SVG. C# Demo Codes for PDF Conversions. 1. Upload a file to your web viewer.
batch convert pdf to html; convert pdf to html form
C# PDF Page Insert Library: insert pages into PDF file in C#.net
both web server-side application and Windows Forms. Ability to add PDF page number in preview. Offer PDF page break inserting function. Free components and online
convert pdf to html for online; best pdf to html converter
BettinaGr
¨
un,AchimZeileis
5
\begin{question}
A machine fills milk into $500$ml packages. It is suspected that the
machine is not working correctly y and d that the e amount t of milk filled differs
from the e setpoint t $\mu_0 0 = = 500$. . A A sample of $226$ $ packages
filled by the e machine are e collected. The sample mean $\bar{y}$ is equal to
$517.2$ and the sample variance $s^2_{n-1}$ is equal to
$262.56$.
Test the e hypothesis s that t the e amount filled d corresponds s on average to the
setpoint. What is the e absolute e value of the $t$~test statistic?
\end{question}
\begin{solution}
The $t$~test statistic is calculated by:
\begin{eqnarray*}
t & & = = & \frac{\bar y - - \mu_0}{\sqrt{\frac{s^2_{n-1}}{n}}}
= \frac{517.2 - 500}{\sqrt{\frac{262.56}{226}}}
= 15.958.
\end{eqnarray*}
The absolute value of f the e $t$~test statistic is thus equal l to
$15.958$.
\end{solution}
%% META-INFORMATION
%% \extype{num}
%% \exsolution{15.958}
%% \exname{t statistic}
%% \extol{0.01}
Table2: L
A
T
E
XoutputofSweave("tstat.Rnw").
\exname{}: anameordescription. . Thisissomeshortinformativetext,onlyusedfor
printingofsolutionswithinR.
\extol{}: optional l tolerance limit(s). . For r numeric solutions a tolerance limit can
bespecified; by y default it is assumedto be 0. . This s canbeusefulfor theautomatic
evaluation of numeric solutions s if some deviation n from the correct t answer is allowed
(e.g., due e to rounding errors). . If f a a single e tolerance e value is s supplied, , a a symmetric
intervalaroundthetruevalueisused.(Version1oftheexamspackagealsosupported UPDATE
asymmetrictoleranceintervalswhentwotolerancevalueswereprovided. However,this
hasnotbeenimplementedforanyoftheversion2interfaces.)
C# PDF Convert to Jpeg SDK: Convert PDF to JPEG images in C#.net
a more suitable choice for publishing in web services than Using this C#.NET PDF to JPEG conversion library C# developers can easily and quickly convert a large
how to convert pdf to html email; convert pdf to website
C# PDF Convert to SVG SDK: Convert PDF to SVG files in C#.net, ASP
Instantly convert all PDF document pages to SVG image files in C#.NET class Perform high-fidelity PDF to SVG conversion in both ASP.NET web and WinForms
export pdf to html; convert pdf to url
6
AutomaticGenerationofExamsinR
1. Problem
Amachinefillsmilkinto500mlpackages.Itissuspectedthatthemachineisnotworking
correctlyandthattheamountofmilkfilleddiffersfromthesetpointµ
0
=500.Asample
of226packagesfilledbythemachinearecollected.Thesamplemean¯yisequalto517.2
andthesamplevariances
2
n−1
isequalto262.56.
Testthehypothesisthattheamountfilledcorrespondsonaveragetothesetpoint.What
istheabsolutevalueofthetteststatistic?
Solution
Thetteststatisticiscalculatedby:
t =
¯y−µ
0
s2
n−1
n
=
517.2−500
262.56
226
=15.958.
Theabsolutevalueofthetteststatisticisthusequalto15.958.
Table3: Displayofprocessedexercisefromexams2pdf("tstat.pdf").
Themeta-informationisreadfromtheL
A
T
E
Xfile(e.g.,asinTable2)andhenceallvaluescan
be dynamicallycomputedusing\Sexpr{}. . Typically,thiswillbenecessaryforthecorrect
solution,but similarlythedescriptivename,thetoleranceallowed,or eventhe typeofthe
questioncouldbedata-drivenanddeterminedbytheDGP.
Theuserdoesnothavetogofromthe Sweave file(Table1)tothe LAT
E
Xfile(Table2)to
thePDF file(Table3)“by hand”. . Thefunctionexams2pdf()frompackageexams s carries
outallofthesestepsautomatically. (Inversion1ofthepackagethefunctionexams()was
UPDATE
provided. Whilethisisstillcontainedinthepackage,itisrecommendedtousethenewerand
moreflexibleexams2pdf()fornewprojects.)
R> library("exams")
R> set.seed(1090)
R> tstat_ex <- exams2pdf("tstat.Rnw")
Afterloadingthepackage,exams2pdf()iscalledwiththeSweavefilename. ThefinalPDF
fileisdisplayedonscreenbydefault(forfurtheroptionsseeSection4).ThePDFviewerused
dependsontheoperatingsystem:OnWindows,theapplicationspecifiedinthesystem’sfile
associationsisused. Onothersystems(e.g.,LinuxorMacOS),thePDFviewerspecifiedin
theoptions(seegetOption("pdfviewer"))isstarted. exams2pdf()returnsalistofexams
whichisalistofexercises(seeZeileisetal.2014,fordetails).Toextractan“exams_metainfo”
objectforprettyprintinginR,thefunctionexams_metainfo()canbeused:
R> exams_metainfo(tstat_ex)
C# Image: How to Annotate Document Image in Web Viewer with C#.NET
annotations on source image or document page within C# RasterEdge Web Viewer Control provides C# developers with options on documents in TIFF, PDF, Office Word
converting pdf to html email; convert pdf into web page
BettinaGr
¨
un,AchimZeileis
7
exam1
1. t t statistic: : 15.958 (15.948--15.968)
3. Combiningexercises: : ThemasterL
A
T
E
Xfile
To produce e the PDF F for an exam, the exercises s need to o be weaved, , tied d together in the
masterLAT
E
XfileandsubsequentlyprocessedtoPDF.Moreprecisely,exams2pdf()takesthe
followingapproach:
1. CollectallSweavefilesfortheexercises,themasterLAT
E
Xfile(s)andpotentiallyaddi-
tionallyspecifiedinputfiles.
2. Copyallfilestoa(temporary,bydefault)directory.
3. RunSweave()foreachexercise.
4. ProduceacopyofthemasterLAT
E
Xfile(s)inwhichcertaincontrolstructuresaresub-
stitutedbydynamicallygeneratedL
A
T
E
Xcommands(e.g.,forincludingtheexercises).
5. Runtexi2dvi()foreachmasterL
A
T
E
Xfile.
6. StoretheresultingPDFfile(s)inanoutputdirectoryordisplayitonthescreen(fora
singlefileonly,bydefault).
Thus,theonlythingneededtocombineseveralindependentexercisestoanexamisamaster
L
A
T
E
Xfile.Itsbasicstructureisratherstraightforwardbutformoreelaboratelayoutsitcan
becomequite complex. . Packageexams s provides various examples of master L
A
T
E
Xfiles in
theinst/tex/directoryofthesourcepackage.Thesimplestoneisplain.tex(seeTable4)
whichisdescribedheretoprovideafirstoverview.
Thestructureofplain.texis rather straightforward: : First,thedocument t class is defined
andthennecessaryadd-onpackagesareloaded.
3
Thentheenvironmentsforquestionand
solutionaredefined(aspartofanitemizeorenumeratelist). Finally,thedocumentstarts
andconsistsonlyofanenumeratelist. InStep4ofthealgorithmdescribedabove,thecontrol
command%% \exinput{exercises}is s replacedby(asequenceof) \input{filename},e.g.,
\input{exercise1.tex}
4
forthefirstexerciseetc.Optionally,the%% \exinput{exercises}
comment can also be omitted in the e template. . Then, , the user r can n place his/her own
\input{exercise1.tex}, \input{exercise2.tex}, , ...in n the e master r LAT
E
Xfile. This s re-
quiresknowingthecorrectnumberofexercisesbutaddstheflexibilityofincludingarbitrary
text/formattingbetweentheexercises.
Thus,allappearanceoptionscanbecontrolledintheLAT
E
Xcodeofthemasterfile,e.g.,by
changingthedefinitionsofthequestion/solutionenvironments orbymodifyingthecode
aroundthe\exinput{}command.Asanexample,onemightwanttoshowonlythequestions
3
NotethatSweave.styisincludedfordisplayingRoutput. texi2dvi()ensuresthatthisstylefilewillbe
foundbyincludingR’stexmfdirectoryintheTEXINPUTSpath.
4
Leadingzerosareaddedifnhas morethan onedigit,e.g.,exercise01.texif therearebetweentenand
99exercises.
8
AutomaticGenerationofExamsinR
\documentclass[a4paper]{article}
\usepackage{a4wide,color,Sweave,url,amsmath,booktabs,longtable}
\newenvironment{question}{\item \textbf{Problem}\newline}{}
\newenvironment{solution}{\textbf{Solution}\newline}{}
\newenvironment{answerlist}{\renewcommand{\labelenumi}{(\alph{enumi})}
\begin{enumerate}}{\end{enumerate}}
\begin{document}
\begin{enumerate}
%% \exinput{exercises}
\end{enumerate}
\end{document}
Table4: AsimplemasterL
A
T
E
Xfile: plain.tex.
andhidethesolutionsinthePDF.Thisiseasilyobtainedbychangingthedefinitionofthe
solutionenvironmentto\newenvironment{solution}{\comment}{\endcomment}.
Thestructuredescribedsofariscompletelystatic,exceptforthe\exinput{}command. In
fact,exercisesisnottheonlyargumentallowed;atthemomenttwofurtherargumentscan
beusedtomodifyaspectsofthemasterLAT
E
Xfiledynamically:
\exinput{exercises}: Inclusionofexercises.
Replacedby: \input{filename}(oneforeachexercise).
Example:\input{exercise1.tex}.
\exinput{questionnaire}:Inclusionofquestionnaires,e.g.,forcoversheets.
Replacedby:\exnum{...},\exmchoice{...},or\exstring{...},respectively(onefor
eachexercise).
Example:\exnum{}{}{}{}{1}{5}{9}{5}{8}.
\exinput{header}: Furthercommandsanddefinitions.
Replacedby: \command{value}(oneforeachheadercommand).
Example:\Date{2015-11-24}.
Forthelattertwo,themasterLAT
E
Xfilehastodefinethecommandsthatareusedinthere-
placementstep,e.g.,\exnumhastobeacommandthattakesninearguments(correspondingto
sixandthreedigitsbeforeandafterthedecimalpointfornumericsolutions),\exmchoicehas
totakeonerequiredandoneormoreoptionalargumentssuchas\exmchoice{X}[][X][][]
(correspondingtothelogicalmultiple-choiceanswers)and\exstringhastotakeonlyonear-
gument(correspondingtothesolutionstring).(Theimplementationofmchoicewasslightly
UPDATE
differentinversion1 of thepackage whereonlyafixednumberof five multiple choiceswas
supported.) Fortheheader,arbitrarycommandscanbesetup,seeSection4fordetails.
BettinaGr
¨
un,AchimZeileis
9
Twomaster L
A
T
E
X files that t illustrate all l of the commands above are provided in exams:
exam.tex and d solution.tex. . exam.tex x canbe usedto generate examsincluding acover
sheet for students to fill l in their names s as s wellas s their r answers to the problems (hiding
solutionsfortheexercises,obviously). solution.texproducesPDFfilescontainingacover
sheetsimilar to exam.texbut withthecorrectanswersalreadyfilledin. . Furthermore,the
solutionenvironmentsaredisplayedforeachexercise.
4. Applicationandcustomization
In the simple case where only y asingleSweave exerciseis processedrunning exams2pdf()
essentially corresponds tofirst calling Sweave() andthen n texi2dvi() ) onthe fileafter in-
cludingitinamaster LAT
E
Xfile. Thisis s quite convenient,especially fornon-experts(inR
and/or LAT
E
X), but t beyond d that t not much h simplificationis gainedby y exams2pdf(). . The
mainadvantagesofthefunction,however,areitsflexibilityandcustomizability: Itcontrols
the(dynamic)combinationoftheSweaveandL
A
T
E
Xfilesandallowsfor
constructionofexamswithstratifiedsamplingofexercises,
automaticgenerationofmultiplecopies(potentiallyofmultiplelayouts)withsuitable
namesandstorage,
inclusionofasuitablecoverpagewithanswerfields,
collectionofmeta-informationforproblemsandsolutionsinanRobject.
In the e following, we illustrate e how w exams2pdf() can be employed d to exploit t all l of f these
features. First,theinterfaceofexams2pdf()isbrieflydescribedbeforeusingittogenerate
asmallsetofexamswithcorrespondingsolutions. Functionexams2pdf()hasthefollowing
arguments:
exams2pdf(file, n = 1L, nsamp p = = NULL, , dir r = ".", template = "plain",
inputs = = NULL, , header r = list(Date = = Sys.Date()), name e = NULL,
control = NULL, encoding = "", quiet = TRUE, transform = = NULL,
edir = = NULL, , tdir = = NULL, , sdir = = NULL, , verbose = = FALSE,
points = = NULL, , ...)
wherefilespecifiesalist/vectorofexerciseSweavefiles(seeSection2),templateisthename
ofthemasterLAT
E
Xfile(seeSection3),andnisthenumberofrandomreplications.There-
mainingargumentscontroldetailsoftheprocessing,e.g.,thedirectoriesforinput/outputfiles.
Atechnicalmanualisavailableonthehelppage?exams2pdf,abriefhands-onintroduction
toselectedargumentsisgivenbelow:
file: ThisiseitheracharactervectorcontainingthefilenamesofSweaveexercisesoralist
ofsuchvectors,e.g.,
R> myexam m <- - list("boxplots",
+
c("confint", "ttest", , "tstat"),
+
c("anova", "regression"),
+
"scatterplot",
+
"relfreq")
10
AutomaticGenerationofExamsinR
Examsgeneratedfrommyexamalwayshavefiveexercises:"boxplots","scatterplot",
and"relfreq" arealways includedbutthe secondexercise is randomly drawnfrom
"confint","ttest", "tstat". . Similarly,thethirdexerciseis s randomly chosenfrom
"anova" and d "regression". . This s stratified d sampling strategy y is s usefulif there are
severalexercisesrelatedtothesametopic,orseveralexercisesforthesamestatistical
techniqueswithdifferent“stories”.Ifonlyasinglevector(ratherthanalist)offilenames
isspecified,eachexerciseisalwaysincludedinthefinaloutputfile.Theextension.Rnw
canbeomittedfromthefilenamesandthecorrespondingfilesshouldeitherbeinthe
localdirectory,theedirdirectoryorintheexercisesdirectoryoftheinstalledpackage.
n: Numberofrandomlygeneratedexams.
nsamp: Numberofelementssampledfromeachlist t elementoffile. . Samplingwithoutre-
placementisused(ifpossible).
dir: OutputdirectoryforstoringtheresultingPDFfiles(andmeta-information). Ifonlya
singlePDFfileisgenerated,thiscanbeomitted(andtheresultisdisplayeddirectlyon
thescreen),otherwiseithastobespecified.
template: A(vectorof) ) masterLAT
E
Xfile(s). Ifmorethanonetemplate e isspecified,one
PDFoutput fileiscreatedforeachineachofthenruns. . Theextension.texcanbe
omittedinthefilenameandthecorrespondingfilesshouldeitherbeinthelocaldirectory
(orprovidedwiththefullpath)orinthetexdirectoryoftheinstalledpackage.
header: Additional L
A
T
E
Xcommands for replacement of \exinput{header} in n the master
LAT
E
Xfile.Ithastobealist()ofcommand = = valuepairs,wherevalue e caneitherbe
astaticstringorafunctioncomputingastringfromtheindexioftheithexam.
Furtherarguments: inputs s canspecifyalist offilesneededduringthe LAT
E
Xcompilation,
e.g., private .sty y files etc. . name e is the(vector of) prefix(es) for thefinalPDF files.
quiet = TRUEsuppressesoutputwhencallingSweave()andtexi2dvi(). . ediristhe
path to the exercisedirectory(defaulting to the current t workingdirectory). . tdir r is
thetemporary(bydefault)directoryintowhichallfilesarecopiedandwhereSweave()
andtexi2dvi()arecalled.sdiristhedirectory(tempoararybydefault)inwhichsup-
plementaryfiles(suchasgraphics)arestored.verbose = = TRUEdisplayssomeprogress
informationandcontrolallowsafewfurthercontroloptions(seealsobelow).
Forthesubsequentexample,weuseatemporaryoutputdirectory(butthereadercouldeasily
changeodirtosomelocaldirectory).
R> odir <- tempfile()
AssumethatwewantadifferentIDforeachexam.Toaccomplishthis,wedefineafunction
whichisusedtosubstituteadifferent\ID{myexamii}commandintheheaderofeachexam.
(TheLAT
E
Xcommand\ID{}hastobedefinedinthemasterLAT
E
Xfiles.)
R> getID D <- - function(i)
+
paste("myexam", gsub(" ", "0", format(i, , width h = = 2)), sep p = "")
R> getID(1)
Documents you may be interested
Documents you may be interested