R and Latex Code in the Service of Exam Questions
The following webpage is under development and will grow with more information. The author abides by the GPL (>= 2) license provided by the "ProfessR" package by showing basic code, but not altering it. The code that is provided here is governed by the MIT license, copyright 2018, while respecting the GPL (>=2) license.
Rationale
Apart from the limited choices of open sourced, online curriculum building for adult ESL students (viz. elcivics.com), there is a current need to create open-sourced assessments for various levels of student understandings of the English language. While the U.S. Citizenship and Immigration Services (https://www.uscis.gov/citizenship) has valuable lessons for beginning and intermediate ESL civics learners, there exists a need to provide more robust assessments, especially for individuals repeating ESL-based civics courses. This is because the risks and efforts involved in applying for U.S. citizenship serve as a motivating factor for some permanent residents and others to come into an ESL civics class with many hours of preparation prior to any seat work. This is true especially when dealing with the 100 questions listed in U.S. form M-638 (revised 1-17) (If you are not familiar with M-638, you may type the term into a web browser for more information). Therefore, solving the problem of creating large question banks for multiple versions of tests is of paramount importance. The problem can be solved easily with highly reliable open sourced software.
Installing Tex and R
The final test outputs require an installation of BasicTex, a smaller distribution of MacTeX. You can find more about installing BasicTex here: http://www.tug.org/mactex/. For more information, see CTAN at https://www.ctan.org/pkg/latex.
The other prerequisite is to install R. To do this, go to the CRAN network https://cran.r-project.org/. You will also need to install the ProfessR package. Go to https://cran.r-project.org/doc/manuals/r-release/R-admin.html and read subsection 6.3. It is highly advised that you install packages from within the R terminal.
Getting Started
To the end of providing quick, summative assessments, this page shows the reader how to incorporate the “ProfessR” package in R to generate a PDF exam file (and multiple variations thereof). A copy of the "ProfessR" package description may be found on https://cran.r-project.org/web/packages/ProfessR/ProfessR.pdf, but useRs will find that it is not a seamless approach from start to PDF generation. The underlying aim of the "ProfessR" package is to read in UTF-8 .txt files, generate a question bank object, and create an exam from one or more question banks, with the option of randomly assigning questions to tests that are generated in a LaTeX file. As the "ProfessR" documentation is scant, this page will fill in missing details to guide the reader.
The example below shows the formatting for the .txt file that will be loaded up into the R environment to become an object readable by the ProfessR package.
Sample test item in a .txt file prepared for ProfessR in R
QUESTION: What is one capital of your state?
a) Houston
ANSWER: b) Austin
c) Dallas
d) San Antonio
You can find files for Unit 1 and 2 to generate the civics exam here.
pacman::p_load(ProfessR,magrittr)
QB1 <- ProfessR::Get.testbank("~/Desktop/Civics/civics_unit_two.txt")
head(QB1[[1]])
QB1 <- ProfessR::Get.testbank("~/Desktop/Civics/civics_unit_two.txt")
head(QB1[[1]])
Output
## $Q
## [1] "What did the Declaration of Independence do?"
##
## $A
## [1] "a)\tdeclared that the colonies owed thanks to Britain "
## [2] "b) announced the colonies' independence"
## [3] "c)\tstated that the colonies were well represented"
## [4] "d)\tdiscussed that the colonies needed more troops."
##
## $a
## [1] "ANSWER: b) announced the colonies' independence"
##
## $numANS
## [1] 2
##
## $FIG
## NULL
## [1] "What did the Declaration of Independence do?"
##
## $A
## [1] "a)\tdeclared that the colonies owed thanks to Britain "
## [2] "b) announced the colonies' independence"
## [3] "c)\tstated that the colonies were well represented"
## [4] "d)\tdiscussed that the colonies needed more troops."
##
## $a
## [1] "ANSWER: b) announced the colonies' independence"
##
## $numANS
## [1] 2
##
## $FIG
## NULL
Results
The code returns a print out of the first part of the list returned by the algorithm. 1. The first indexed list item includes the $Q (question) and the $A (answer) components of the sublist 2. The correct answer is included, 3. The number of correct answers is also included.
For more information on the structure of the object, call the structure command on QB1.
ProfessR::make.exam(QB1, ofile = "~/Desktop/Civics/examS.tex")
This code creates the file “exam1.tex” in the designated folder. In this stage, the document will look like this:
Next, the following latex code should be sandwiched between the raw text on both sides
\documentclass[12pt, oneside]{article}
\usepackage{geometry}
\geometry{letterpaper}
\usepackage{multicol}
\usepackage{amssymb}
\title{Civics: Unit 1 Exam}
\author{Name: }
%\date{} % Activate to display a given date or no date
\begin{document}
\maketitle
\begin{multicols}{2}
[
\subsubsection*{Directions} Fill in the answer sheet with the
letter that best answers the question. In some cases there will
be more than one correct answer.
]
\begin{enumerate}
PUT THE RAW OUTPUT HERE.
\end{enumerate}
\end{multicols}
\end{document}
Notes on the Latex Code
The raw code provided by the ProfessR package does not include the general parameters for the enumerate function. The enumerate function is essential to set the code in place.
\begin{enumerate}
\end{enumerate}
The code must then be inserted into a general document template. For ease of use, the raw code has been inserted into the LaTeX article class. The raw data should be inserted over the “PUT THE RAW OUTPUT HERE” line. To do this, simply copy and paste from the raw file.
To run the code in LaTeX, simply typeset in LaTeX.