Title: | Random Exercises and Exams Generator |
---|---|
Description: | The main purpose of this package is to streamline the generation of exams that include random elements in exercises. Exercises can be defined in a table, based on text and figures, and may contain gaps to be filled with provided options. Exam documents can be generated in various formats. It allows us to generate a version for conducting the assessment and another version that facilitates correction, linked through a code. |
Authors: | Jose Samos [aut, cre] , Universidad de Granada [cph] |
Maintainer: | Jose Samos <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.0 |
Built: | 2024-11-27 06:31:50 UTC |
Source: | CRAN |
Creates an empty exercise csv file.
create_exercise_csv(file, sep = ",")
create_exercise_csv(file, sep = ",")
file |
A string, name of a text file. |
sep |
Column separator character. |
A string.
Other support functions:
create_exercise_data_frame()
,
create_exercise_excel()
,
read_exercise_csv()
,
read_exercise_excel()
,
set_pending_answers()
,
vector_to_string()
,
write_exercise_csv()
file <- create_exercise_csv(file = tempfile(fileext = '.csv'))
file <- create_exercise_csv(file = tempfile(fileext = '.csv'))
Creates an empty exercise data frame.
create_exercise_data_frame()
create_exercise_data_frame()
A data frame.
Other support functions:
create_exercise_csv()
,
create_exercise_excel()
,
read_exercise_csv()
,
read_exercise_excel()
,
set_pending_answers()
,
vector_to_string()
,
write_exercise_csv()
df <- create_exercise_data_frame()
df <- create_exercise_data_frame()
Creates an empty exercise Excel file.
create_exercise_excel(file)
create_exercise_excel(file)
file |
A string, name of a text file. |
A string.
Other support functions:
create_exercise_csv()
,
create_exercise_data_frame()
,
read_exercise_csv()
,
read_exercise_excel()
,
set_pending_answers()
,
vector_to_string()
,
write_exercise_csv()
file <- create_exercise_excel(file = tempfile(fileext = '.xlsx'))
file <- create_exercise_excel(file = tempfile(fileext = '.xlsx'))
Defines an exercise with random components.
define_an_exercise(ex, type, statement, image, image_alt, answer, ...) ## S3 method for class 'exam' define_an_exercise( ex, type = "", statement = "", image = "", image_alt = "", answer = "", ... )
define_an_exercise(ex, type, statement, image, image_alt, answer, ...) ## S3 method for class 'exam' define_an_exercise( ex, type = "", statement = "", image = "", image_alt = "", answer = "", ... )
ex |
An 'exam' object. |
type |
A character, 'p' indicates whether the exercise starts on a new page. |
statement |
A string, statement of the exercise. |
image |
A string, optional, image file to include in the exercise. |
image_alt |
A string, description of the image to include in the exercise. |
answer |
A string, correct answer to the exercise. |
... |
A string, options for the gaps in the exercise. |
If an image is included in the exercise, text in the 'image_alt' field associated with it must also be included.
Following the answer, options can be defined to fill in the gaps that have been specified in the exercise.
Both the answer and the options are formed by a vector of strings, from which one is chosen to formulate the exercise and select the answer. To represent a vector of strings in a cell, the function 'vector_to_string()' is used, which includes a separator ("<|>") between the vector elements to generate a string.
An 'exam'.
Other exercise definition:
define_exercises()
,
define_exercises_from_csv()
,
define_exercises_from_excel()
rmd <- system.file("extdata/template01.Rmd", package = "rexer") ex <- exam( rmd = rmd, examinees = NULL, instances_num = 10, random = TRUE, reorder_exercises = TRUE, select_n_exercises = NULL ) |> define_an_exercise( type = 'p', statement = 'What is the three-letter country code (ISO 3166-1 alpha-3) for the country represented in the figure below?', image = paste0(system.file("extdata/figures", package = "rexer"), "/", '[[1]]'), image_alt = 'Country outline.', answer = c('ESP', 'CHL', 'NZL', 'ITA'), c('spain.png', 'chile.png', 'new_zealand.png', 'italy.png') )
rmd <- system.file("extdata/template01.Rmd", package = "rexer") ex <- exam( rmd = rmd, examinees = NULL, instances_num = 10, random = TRUE, reorder_exercises = TRUE, select_n_exercises = NULL ) |> define_an_exercise( type = 'p', statement = 'What is the three-letter country code (ISO 3166-1 alpha-3) for the country represented in the figure below?', image = paste0(system.file("extdata/figures", package = "rexer"), "/", '[[1]]'), image_alt = 'Country outline.', answer = c('ESP', 'CHL', 'NZL', 'ITA'), c('spain.png', 'chile.png', 'new_zealand.png', 'italy.png') )
Each row in the text data frame is interpreted as an exercise. We only need to define the columns that we are going to use; the rest of the columns are taken by default.
define_exercises(ex, df) ## S3 method for class 'exam' define_exercises(ex, df)
define_exercises(ex, df) ## S3 method for class 'exam' define_exercises(ex, df)
ex |
An 'exam' object. |
df |
A data frame containing exercises. |
Both the answer and the options are formed by a vector of strings, from which one is chosen to formulate the exercise and select the answer. To represent a vector of strings in a cell, the function 'vector_to_string()' is used, which includes a separator ("<|>") between the vector elements to generate a string.
An 'exam'.
Other exercise definition:
define_an_exercise()
,
define_exercises_from_csv()
,
define_exercises_from_excel()
rmd <- system.file("extdata/template01.Rmd", package = "rexer") exercises <- system.file("extdata/exercises.csv", package = "rexer") q <- read_exercise_csv(exercises) ex <- exam( rmd = rmd, examinees = NULL, instances_num = 10, random = TRUE, reorder_exercises = TRUE, select_n_exercises = NULL ) |> define_exercises(q)
rmd <- system.file("extdata/template01.Rmd", package = "rexer") exercises <- system.file("extdata/exercises.csv", package = "rexer") q <- read_exercise_csv(exercises) ex <- exam( rmd = rmd, examinees = NULL, instances_num = 10, random = TRUE, reorder_exercises = TRUE, select_n_exercises = NULL ) |> define_exercises(q)
Each row in the text file is interpreted as an exercise. We only need to define the columns that we are going to use; the rest of the columns are taken by default.
define_exercises_from_csv(ex, file, sep) ## S3 method for class 'exam' define_exercises_from_csv(ex, file, sep = ",")
define_exercises_from_csv(ex, file, sep) ## S3 method for class 'exam' define_exercises_from_csv(ex, file, sep = ",")
ex |
An 'exam' object. |
file |
A string, name of a text file. |
sep |
Column separator character ("," or ";"). |
Both the answer and the options are formed by a vector of strings, from which one is chosen to formulate the exercise and select the answer. To represent a vector of strings in a cell, the function 'vector_to_string()' is used, which includes a separator ("<|>") between the vector elements to generate a string.
An 'exam'.
Other exercise definition:
define_an_exercise()
,
define_exercises()
,
define_exercises_from_excel()
rmd <- system.file("extdata/template01.Rmd", package = "rexer") exercises <- system.file("extdata/exercises.csv", package = "rexer") ex <- exam( rmd = rmd, examinees = NULL, instances_num = 10, random = TRUE, reorder_exercises = TRUE, select_n_exercises = NULL ) |> define_exercises_from_csv(exercises)
rmd <- system.file("extdata/template01.Rmd", package = "rexer") exercises <- system.file("extdata/exercises.csv", package = "rexer") ex <- exam( rmd = rmd, examinees = NULL, instances_num = 10, random = TRUE, reorder_exercises = TRUE, select_n_exercises = NULL ) |> define_exercises_from_csv(exercises)
Each row in the Excel file is interpreted as an exercise. We only need to define the columns that we are going to use; the rest of the columns are taken by default.
define_exercises_from_excel(ex, file, sheet_index, sheet_name) ## S3 method for class 'exam' define_exercises_from_excel(ex, file, sheet_index = NULL, sheet_name = NULL)
define_exercises_from_excel(ex, file, sheet_index, sheet_name) ## S3 method for class 'exam' define_exercises_from_excel(ex, file, sheet_index = NULL, sheet_name = NULL)
ex |
An 'exam' object. |
file |
A string, name of an Excel file. |
sheet_index |
A number, sheet index in the workbook. |
sheet_name |
A string, sheet name. |
In addition to the file, we can indicate the sheet by its name or index. If we do not indicate anything, it considers the first sheet.
Both the answer and the options are formed by a vector of strings, from which one is chosen to formulate the exercise and select the answer. To represent a vector of strings in a cell, the function 'vector_to_string()' is used, which includes a separator ("<|>") between the vector elements to generate a string.
An 'exam'.
Other exercise definition:
define_an_exercise()
,
define_exercises()
,
define_exercises_from_csv()
rmd <- system.file("extdata/template01.Rmd", package = "rexer") exercises <- system.file("extdata/exercises.xlsx", package = "rexer") ex <- exam( rmd = rmd, examinees = NULL, instances_num = 10, random = TRUE, reorder_exercises = TRUE, select_n_exercises = NULL ) |> define_exercises_from_excel(exercises)
rmd <- system.file("extdata/template01.Rmd", package = "rexer") exercises <- system.file("extdata/exercises.xlsx", package = "rexer") ex <- exam( rmd = rmd, examinees = NULL, instances_num = 10, random = TRUE, reorder_exercises = TRUE, select_n_exercises = NULL ) |> define_exercises_from_excel(exercises)
Creates an 'exam' object.
exam( rmd = NULL, examinees = NULL, instances_num = 1, random = TRUE, reorder_exercises = TRUE, select_n_exercises = NULL )
exam( rmd = NULL, examinees = NULL, instances_num = 1, random = TRUE, reorder_exercises = TRUE, select_n_exercises = NULL )
rmd |
A string representing the path to the Rmd file, the exam template. |
examinees |
A vector of strings, representing the names of instances to generate. |
instances_num |
An integer, representing the number of instances to generate if the examinee names are not provided. |
random |
A boolean, indicating whether to generate instances randomly or sequentially. |
reorder_exercises |
A boolean, indicating whether to reorder exercises in the exam. |
select_n_exercises |
An integer, representing the number of exercises to include. |
A test is based on an Rmd template that has predefined parameters whose values are filled in using the functions of this object. In the 'rmd' parameter, we specify the template file.
From the template, we generate multiple instances of the exam. We can specify the instances to generate in two ways: by indicating a vector of examinee names (using the 'examinees' parameter) or by specifying the number of instances to generate (using the 'instances_num' parameter). If both are indicated, the examinee names take precedence.
We can generate the instances either randomly or sequentially, depending on the instance number we generate. This is controlled by the 'random' parameter.
Additionally, in each test, we can include the exercises in the same order as they are defined or in random order. This is indicated by the 'reorder_exercises' parameter.
Finally, using the 'select_n_exercises' parameter, we can specify the number of exercises to include in each test. From all available exercises, the quantity specified in this parameter will be randomly selected. By default, all defined exercises are included.
An 'exam' object.
Other exam definition:
generate_correction_document()
,
generate_document()
rmd <- system.file("extdata/template01.Rmd", package = "rexer") ex <- exam( rmd = rmd, examinees = NULL, instances_num = 10, random = TRUE, reorder_exercises = TRUE, select_n_exercises = NULL )
rmd <- system.file("extdata/template01.Rmd", package = "rexer") ex <- exam( rmd = rmd, examinees = NULL, instances_num = 10, random = TRUE, reorder_exercises = TRUE, select_n_exercises = NULL )
From an exam object, we can generate instances that serve as support for the correction of the exam. Each instance will include the answers, if they are indicated, associated with the exercises. In any case, the randomly included part of the exam will be highlighted.
generate_correction_document(ex, out_dir, output_format, encoding, new_pages) ## S3 method for class 'exam' generate_correction_document( ex, out_dir = NULL, output_format = "pdf_document", encoding = "UTF-8", new_pages = NULL )
generate_correction_document(ex, out_dir, output_format, encoding, new_pages) ## S3 method for class 'exam' generate_correction_document( ex, out_dir = NULL, output_format = "pdf_document", encoding = "UTF-8", new_pages = NULL )
ex |
An 'exam' object. |
out_dir |
A string indicating the output folder. |
output_format |
A vector of strings specifying the desired output formats. |
encoding |
A string specifying the encoding. |
new_pages |
A string with the values 'all', 'none', or 'NULL'. |
To do this, we specify the folder where the documents will be generated (using parameter 'out_dir'), the output format (using parameter 'output_format'), the encoding (using parameter 'encoding'), and whether we want each exercise to start on a new page, include exercises until the pages are filled, or preserve the definition of the exercise in this regard (using parameter 'new_pages').
An 'exam' object.
Other exam definition:
exam()
,
generate_document()
## Not run: rmd <- system.file("extdata/template01.Rmd", package = "rexer") exercises <- system.file("extdata/exercises.csv", package = "rexer") ex <- exam( rmd = rmd, examinees = NULL, instances_num = 1, random = TRUE, reorder_exercises = TRUE ) |> define_exercises_from_csv(exercises) |> generate_correction_document(out_dir = tempdir()) ## End(Not run)
## Not run: rmd <- system.file("extdata/template01.Rmd", package = "rexer") exercises <- system.file("extdata/exercises.csv", package = "rexer") ex <- exam( rmd = rmd, examinees = NULL, instances_num = 1, random = TRUE, reorder_exercises = TRUE ) |> define_exercises_from_csv(exercises) |> generate_correction_document(out_dir = tempdir()) ## End(Not run)
From an exam object, we generate different instances of the exam to deliver to the individuals being examined. To do this, we need to specify the folder where they will be generated (using parameter 'out_dir'), the output format (using parameter 'output_format'), the encoding (using parameter 'encoding'), and whether we want each exercise to start on a new page, include exercises until the pages are filled, or preserve the definition of the exercise in this regard (using parameter ‘new_pages' with the values ’all', 'none', or NULL).
generate_document(ex, out_dir, output_format, encoding, new_pages) ## S3 method for class 'exam' generate_document( ex, out_dir = NULL, output_format = "pdf_document", encoding = "UTF-8", new_pages = NULL )
generate_document(ex, out_dir, output_format, encoding, new_pages) ## S3 method for class 'exam' generate_document( ex, out_dir = NULL, output_format = "pdf_document", encoding = "UTF-8", new_pages = NULL )
ex |
An 'exam' object. |
out_dir |
A string indicating the output folder. |
output_format |
A vector of strings specifying the desired output formats. |
encoding |
A string specifying the encoding. |
new_pages |
A string with the values 'all', 'none', or NULL. |
An 'exam' object.
Other exam definition:
exam()
,
generate_correction_document()
## Not run: rmd <- system.file("extdata/template01.Rmd", package = "rexer") exercises <- system.file("extdata/exercises.csv", package = "rexer") ex <- exam( rmd = rmd, examinees = NULL, instances_num = 1, random = TRUE, reorder_exercises = TRUE ) |> define_exercises_from_csv(exercises) |> generate_document(out_dir = tempdir(), new_pages = 'all') ## End(Not run)
## Not run: rmd <- system.file("extdata/template01.Rmd", package = "rexer") exercises <- system.file("extdata/exercises.csv", package = "rexer") ex <- exam( rmd = rmd, examinees = NULL, instances_num = 1, random = TRUE, reorder_exercises = TRUE ) |> define_exercises_from_csv(exercises) |> generate_document(out_dir = tempdir(), new_pages = 'all') ## End(Not run)
Reads a csv file of exercises and returns a data frame.
read_exercise_csv(file, sep = ",")
read_exercise_csv(file, sep = ",")
file |
A string, name of a text file. |
sep |
Column separator character. |
A data frame.
Other support functions:
create_exercise_csv()
,
create_exercise_data_frame()
,
create_exercise_excel()
,
read_exercise_excel()
,
set_pending_answers()
,
vector_to_string()
,
write_exercise_csv()
file <- system.file("extdata/exercises.csv", package = "rexer") df <- read_exercise_csv(file)
file <- system.file("extdata/exercises.csv", package = "rexer") df <- read_exercise_csv(file)
Reads an Excel file of exercises and returns a data frame.
read_exercise_excel(file, sheet_index = NULL, sheet_name = NULL)
read_exercise_excel(file, sheet_index = NULL, sheet_name = NULL)
file |
A string, name of a text file. |
sheet_index |
A number, sheet index in the workbook. |
sheet_name |
A string, sheet name. |
In addition to the file, we can indicate the sheet by its name or index. If we do not indicate anything, it considers the first sheet.
A data frame.
Other support functions:
create_exercise_csv()
,
create_exercise_data_frame()
,
create_exercise_excel()
,
read_exercise_csv()
,
set_pending_answers()
,
vector_to_string()
,
write_exercise_csv()
file <- system.file("extdata/exercises.csv", package = "rexer") df <- read_exercise_csv(file)
file <- system.file("extdata/exercises.csv", package = "rexer") df <- read_exercise_csv(file)
The answers we want to process are indicated by the character "?". Fill in the specified answers by generating combinations of the available options to fill the gaps in order, from value 1 to the maximum number of options available: the first option for each of the gaps, the second for each of the gaps, and so on.
set_pending_answers(df)
set_pending_answers(df)
df |
A data frame of exercises. |
A data frame.
Other support functions:
create_exercise_csv()
,
create_exercise_data_frame()
,
create_exercise_excel()
,
read_exercise_csv()
,
read_exercise_excel()
,
vector_to_string()
,
write_exercise_csv()
file <- system.file("extdata/example.csv", package = "rexer") df <- read_exercise_csv(file) df <- set_pending_answers(df)
file <- system.file("extdata/example.csv", package = "rexer") df <- read_exercise_csv(file) df <- set_pending_answers(df)
Insert the separator ("<|>") to later facilitate the reverse operation.
vector_to_string(vector)
vector_to_string(vector)
vector |
A vector of strings. |
A string.
Other support functions:
create_exercise_csv()
,
create_exercise_data_frame()
,
create_exercise_excel()
,
read_exercise_csv()
,
read_exercise_excel()
,
set_pending_answers()
,
write_exercise_csv()
s <- vector_to_string(c('Addition', '+'))
s <- vector_to_string(c('Addition', '+'))
Writes an exercise data frame in a csv file of exercises.
write_exercise_csv(df, file, sep = ",")
write_exercise_csv(df, file, sep = ",")
df |
A data frame. |
file |
A string, name of a text file. |
sep |
Column separator character. |
A string.
Other support functions:
create_exercise_csv()
,
create_exercise_data_frame()
,
create_exercise_excel()
,
read_exercise_csv()
,
read_exercise_excel()
,
set_pending_answers()
,
vector_to_string()
file <- system.file("extdata/example.csv", package = "rexer") df <- read_exercise_csv(file) df <- set_pending_answers(df) write_exercise_csv(df, file = tempfile(fileext = '.csv'))
file <- system.file("extdata/example.csv", package = "rexer") df <- read_exercise_csv(file) df <- set_pending_answers(df) write_exercise_csv(df, file = tempfile(fileext = '.csv'))