Title: | Defining 'Moodle' Elements from R |
---|---|
Description: | The main objective of this package is to support the definition of 'Moodle' elements taking advantage of the power that R offers. In this first version, it allows the definition of quizzes to be included in the question bank. |
Authors: | Jose Samos [aut, cre] , Universidad de Granada [cph] |
Maintainer: | Jose Samos <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.2.0.9000 |
Built: | 2025-01-27 06:12:11 UTC |
Source: | https://github.com/josesamos/moodef |
Creates an empty question csv file.
create_question_csv(file, sep = ",", extended = FALSE)
create_question_csv(file, sep = ",", extended = FALSE)
file |
A string, name of a text file. |
sep |
Column separator character. |
extended |
A Boolean, use extended question definition. |
A string.
Other support functions:
create_question_data_frame()
,
create_question_excel()
,
read_question_csv()
,
read_question_excel()
,
vector_to_string()
file <- create_question_csv(file = tempfile(fileext = '.csv'))
file <- create_question_csv(file = tempfile(fileext = '.csv'))
Creates an empty question data frame.
create_question_data_frame(extended = FALSE)
create_question_data_frame(extended = FALSE)
extended |
A Boolean, use extended question definition. |
A data frame.
Other support functions:
create_question_csv()
,
create_question_excel()
,
read_question_csv()
,
read_question_excel()
,
vector_to_string()
df <- create_question_data_frame()
df <- create_question_data_frame()
Creates an empty question Excel file.
create_question_excel(file, extended = FALSE)
create_question_excel(file, extended = FALSE)
file |
A string, name of a text file. |
extended |
A Boolean, use extended question definition. |
A string.
Other support functions:
create_question_csv()
,
create_question_data_frame()
,
read_question_csv()
,
read_question_excel()
,
vector_to_string()
file <- create_question_excel(file = tempfile(fileext = '.xlsx'))
file <- create_question_excel(file = tempfile(fileext = '.xlsx'))
This function allows users to define an extended question, including metadata, feedback and optional image data.
define_extended_question( qc, category, type, fraction, id, name, author, fb_general, fb_correct, fb_partially, fb_incorrect, question, image, image_alt, answer, a_1, a_2, a_3, a_4, a_5, a_6, a_7, fb_answer, fb_a_1, fb_a_2, fb_a_3, fb_a_4, fb_a_5, fb_a_6, fb_a_7, tag_1, tag_2, tag_3, tag_4, tag_5, tag_6, tag_7, tag_8, tag_9 ) ## S3 method for class 'question_category' define_extended_question( qc, category = "", type = "", fraction = 0, id = "", name = "", author = "", fb_general = "", fb_correct = "", fb_partially = "", fb_incorrect = "", question = "", image = "", image_alt = "", answer = "", a_1 = "", a_2 = "", a_3 = "", a_4 = "", a_5 = "", a_6 = "", a_7 = "", fb_answer = "", fb_a_1 = "", fb_a_2 = "", fb_a_3 = "", fb_a_4 = "", fb_a_5 = "", fb_a_6 = "", fb_a_7 = "", tag_1 = "", tag_2 = "", tag_3 = "", tag_4 = "", tag_5 = "", tag_6 = "", tag_7 = "", tag_8 = "", tag_9 = "" )
define_extended_question( qc, category, type, fraction, id, name, author, fb_general, fb_correct, fb_partially, fb_incorrect, question, image, image_alt, answer, a_1, a_2, a_3, a_4, a_5, a_6, a_7, fb_answer, fb_a_1, fb_a_2, fb_a_3, fb_a_4, fb_a_5, fb_a_6, fb_a_7, tag_1, tag_2, tag_3, tag_4, tag_5, tag_6, tag_7, tag_8, tag_9 ) ## S3 method for class 'question_category' define_extended_question( qc, category = "", type = "", fraction = 0, id = "", name = "", author = "", fb_general = "", fb_correct = "", fb_partially = "", fb_incorrect = "", question = "", image = "", image_alt = "", answer = "", a_1 = "", a_2 = "", a_3 = "", a_4 = "", a_5 = "", a_6 = "", a_7 = "", fb_answer = "", fb_a_1 = "", fb_a_2 = "", fb_a_3 = "", fb_a_4 = "", fb_a_5 = "", fb_a_6 = "", fb_a_7 = "", tag_1 = "", tag_2 = "", tag_3 = "", tag_4 = "", tag_5 = "", tag_6 = "", tag_7 = "", tag_8 = "", tag_9 = "" )
qc |
A question category object. It should have a |
category |
A character string specifying the category of the question. |
type |
A character string indicating the type of the question. |
fraction |
A number between 0 and 1. |
id |
A unique identifier for the question. |
name |
A character string representing the name of the question. |
author |
The name of the author of the question. |
fb_general |
General feedback for the question. |
fb_correct |
Feedback displayed when the correct answer is selected. |
fb_partially |
Feedback displayed for partially correct answers. |
fb_incorrect |
Feedback displayed for incorrect answers. |
question |
The text of the question. |
image |
Path to an image file associated with the question. |
image_alt |
Alternative text describing the image for accessibility. Required if an image is provided. |
answer |
The correct answer to the question. |
a_1 |
Additional possible answer. |
a_2 |
Additional possible answer. |
a_3 |
Additional possible answer. |
a_4 |
Additional possible answer. |
a_5 |
Additional possible answer. |
a_6 |
Additional possible answer. |
a_7 |
Additional possible answer. |
fb_answer |
Feedback for the correct answer. |
fb_a_1 |
Feedback for additional answer. |
fb_a_2 |
Feedback for additional answer. |
fb_a_3 |
Feedback for additional answer. |
fb_a_4 |
Feedback for additional answer. |
fb_a_5 |
Feedback for additional answer. |
fb_a_6 |
Feedback for additional answer. |
fb_a_7 |
Feedback for additional answer. |
tag_1 |
Tag to categorize the question. |
tag_2 |
Tag to categorize the question. |
tag_3 |
Tag to categorize the question. |
tag_4 |
Tag to categorize the question. |
tag_5 |
Tag to categorize the question. |
tag_6 |
Tag to categorize the question. |
tag_7 |
Tag to categorize the question. |
tag_8 |
Tag to categorize the question. |
tag_9 |
Tag to categorize the question. |
Parameter values that are not defined are taken from the category definition, if they are defined there.
The fraction
attribute is used in various question types to determine how a
specific answer impacts the question's score. Specifically, for incorrect answers
in the multichoice
and truefalse
types, the value calculated by dividing
fraction
by the number of incorrect answers available is considered as the
amount deducted in case of an incorrect response.
In the example provided, we have intentionally used the same structure as in
the define_question()
function to demonstrate that any parameters not needed
do not need to be explicitly defined.
Returns the updated question category object.
Other question definition functions:
define_question()
,
define_questions_from_csv()
,
define_questions_from_data_frame()
,
define_questions_from_excel()
,
generate_xml()
,
generate_xml_file()
,
question_category()
qc <- question_category(category = 'Initial test') |> define_extended_question( question = 'What are the basic arithmetic operations?', answer = 'Addition, subtraction, multiplication and division.', a_1 = 'Addition and subtraction.', a_2 = 'Addition, subtraction, multiplication, division and square root.' )
qc <- question_category(category = 'Initial test') |> define_extended_question( question = 'What are the basic arithmetic operations?', answer = 'Addition, subtraction, multiplication and division.', a_1 = 'Addition and subtraction.', a_2 = 'Addition, subtraction, multiplication, division and square root.' )
Define a question and the possible answers. The type of question is deduced.
define_question(qc, type, question, image, image_alt, answer, ...) ## S3 method for class 'question_category' define_question( qc, type = "", question = "", image = "", image_alt = "", answer = "", ... )
define_question(qc, type, question, image, image_alt, answer, ...) ## S3 method for class 'question_category' define_question( qc, type = "", question = "", image = "", image_alt = "", answer = "", ... )
qc |
A |
type |
A string, question type (if needed). |
question |
A string, statement of the question. |
image |
A string, optional, image file to include in the question. |
image_alt |
A string, description of the image to include in the question. |
answer |
A string, correct answer to the question. |
... |
A string, rest of the answers to the question. |
If we include an image in the question, we must also include text in the alt
field associated with it.
After the correct answer, we can indicate as many answers as we want, if we do not indicate all the parameters, we have to give each answer a parameter name different from the rest of the parameter names.
A question_category
.
Other question definition functions:
define_extended_question()
,
define_questions_from_csv()
,
define_questions_from_data_frame()
,
define_questions_from_excel()
,
generate_xml()
,
generate_xml_file()
,
question_category()
qc <- question_category(category = 'Initial test') |> define_question( question = 'What are the basic arithmetic operations?', answer = 'Addition, subtraction, multiplication and division.', a_1 = 'Addition and subtraction.', a_2 = 'Addition, subtraction, multiplication, division and square root.' )
qc <- question_category(category = 'Initial test') |> define_question( question = 'What are the basic arithmetic operations?', answer = 'Addition, subtraction, multiplication and division.', a_1 = 'Addition and subtraction.', a_2 = 'Addition, subtraction, multiplication, division and square root.' )
Each row in the text file is interpreted as a question. We only have to define the columns that we are going to use, the rest of the columns are taken by default.
define_questions_from_csv(qc, file, sep) ## S3 method for class 'question_category' define_questions_from_csv(qc, file, sep = ",")
define_questions_from_csv(qc, file, sep) ## S3 method for class 'question_category' define_questions_from_csv(qc, file, sep = ",")
qc |
A |
file |
A string, name of a text file. |
sep |
Column separator character. |
For answers where a vector is required, "<|>" is used as a separator of the vector elements.
A question_category
.
Other question definition functions:
define_extended_question()
,
define_question()
,
define_questions_from_data_frame()
,
define_questions_from_excel()
,
generate_xml()
,
generate_xml_file()
,
question_category()
file <- system.file("extdata", "questions.csv", package = "moodef") qc <- question_category(category = 'Initial test', adapt_images = TRUE) |> define_questions_from_csv(file = file)
file <- system.file("extdata", "questions.csv", package = "moodef") qc <- question_category(category = 'Initial test', adapt_images = TRUE) |> define_questions_from_csv(file = file)
Each row in the text data frame is interpreted as a question. We only have to define the columns that we are going to use, the rest of the columns are taken by default.
define_questions_from_data_frame(qc, df) ## S3 method for class 'question_category' define_questions_from_data_frame(qc, df)
define_questions_from_data_frame(qc, df) ## S3 method for class 'question_category' define_questions_from_data_frame(qc, df)
qc |
A |
df |
A data frame. |
For answers where a vector is required, "<|>" is used as a separator of the vector elements.
A question_category
.
Other question definition functions:
define_extended_question()
,
define_question()
,
define_questions_from_csv()
,
define_questions_from_excel()
,
generate_xml()
,
generate_xml_file()
,
question_category()
file <- system.file("extdata", "questions.csv", package = "moodef") df <- read_question_csv(file = file) qc <- question_category(category = 'Initial test', adapt_images = TRUE) |> define_questions_from_data_frame(df)
file <- system.file("extdata", "questions.csv", package = "moodef") df <- read_question_csv(file = file) qc <- question_category(category = 'Initial test', adapt_images = TRUE) |> define_questions_from_data_frame(df)
Each row in the Excel file is interpreted as a question. We only have to define the columns that we are going to use, the rest of the columns are taken by default.
define_questions_from_excel(qc, file, sheet_index, sheet_name) ## S3 method for class 'question_category' define_questions_from_excel(qc, file, sheet_index = NULL, sheet_name = NULL)
define_questions_from_excel(qc, file, sheet_index, sheet_name) ## S3 method for class 'question_category' define_questions_from_excel(qc, file, sheet_index = NULL, sheet_name = NULL)
qc |
A |
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.
For answers where a vector is required, "<|>" is used as a separator of the vector elements.
A question_category
.
Other question definition functions:
define_extended_question()
,
define_question()
,
define_questions_from_csv()
,
define_questions_from_data_frame()
,
generate_xml()
,
generate_xml_file()
,
question_category()
file <- system.file("extdata", "questions.xlsx", package = "moodef") qc <- question_category(category = 'Initial test', adapt_images = TRUE) |> define_questions_from_excel(file = file)
file <- system.file("extdata", "questions.xlsx", package = "moodef") qc <- question_category(category = 'Initial test', adapt_images = TRUE) |> define_questions_from_excel(file = file)
Generate questions xml string
generate_xml(qc) ## S3 method for class 'question_category' generate_xml(qc)
generate_xml(qc) ## S3 method for class 'question_category' generate_xml(qc)
qc |
A |
A string.
Other question definition functions:
define_extended_question()
,
define_question()
,
define_questions_from_csv()
,
define_questions_from_data_frame()
,
define_questions_from_excel()
,
generate_xml_file()
,
question_category()
qc <- question_category(category = 'Initial test') |> define_question( question = 'What are the basic arithmetic operations?', answer = 'Addition, subtraction, multiplication and division.', a_1 = 'Addition and subtraction.', a_2 = 'Addition, subtraction, multiplication, division and square root.' ) xml <- qc |> generate_xml()
qc <- question_category(category = 'Initial test') |> define_question( question = 'What are the basic arithmetic operations?', answer = 'Addition, subtraction, multiplication and division.', a_1 = 'Addition and subtraction.', a_2 = 'Addition, subtraction, multiplication, division and square root.' ) xml <- qc |> generate_xml()
Generate questions xml file
generate_xml_file(qc, file) ## S3 method for class 'question_category' generate_xml_file(qc, file = NULL)
generate_xml_file(qc, file) ## S3 method for class 'question_category' generate_xml_file(qc, file = NULL)
qc |
A |
file |
A string, file name. |
A question_category
.
Other question definition functions:
define_extended_question()
,
define_question()
,
define_questions_from_csv()
,
define_questions_from_data_frame()
,
define_questions_from_excel()
,
generate_xml()
,
question_category()
qc <- question_category(category = 'Initial test') |> define_question( question = 'What are the basic arithmetic operations?', answer = 'Addition, subtraction, multiplication and division.', a_1 = 'Addition and subtraction.', a_2 = 'Addition, subtraction, multiplication, division and square root.' ) |> generate_xml_file(file = tempfile(fileext = '.xml'))
qc <- question_category(category = 'Initial test') |> define_question( question = 'What are the basic arithmetic operations?', answer = 'Addition, subtraction, multiplication and division.', a_1 = 'Addition and subtraction.', a_2 = 'Addition, subtraction, multiplication, division and square root.' ) |> generate_xml_file(file = tempfile(fileext = '.xml'))
question_category
S3 classCreates a question_category
object.
question_category( category = "Default category", first_question_number = 1, copyright = "", license = "", correct_feedback = "Correct.", partially_correct_feedback = "Partially correct.", incorrect_feedback = "Incorrect.", adapt_images = FALSE, width = 800, height = 600, author = "", fraction = 0 )
question_category( category = "Default category", first_question_number = 1, copyright = "", license = "", correct_feedback = "Correct.", partially_correct_feedback = "Partially correct.", incorrect_feedback = "Incorrect.", adapt_images = FALSE, width = 800, height = 600, author = "", fraction = 0 )
category |
A string, category name. |
first_question_number |
An integer, first number to compose the question names. |
copyright |
A string, copyright text to be included in each question that is defined. |
license |
A string, license text to be included in each question that is defined. |
correct_feedback |
A string, feedback on correct answers to each question. |
partially_correct_feedback |
A string, feedback on partially correct answers to each question. |
incorrect_feedback |
A string, feedback on incorrect answers to each question. |
adapt_images |
A boolean, adapt the images so that they are a similar size. |
width |
A integer, width of each image. |
height |
A integer, height of each image. |
author |
A string, author name to be included in each question that is defined. |
fraction |
A number between 0 and 1. |
Defines a category of questions to be included in the Moodle question bank.
It allows us to define the name of the category, the copyright and license literals that will be added to each question, and the feedback literals for correct, partially correct and incorrect questions.
Each question can include an image after the text. We can also configure if we want to automatically transform the images so that they have a standard size that we can also indicate.
The fraction
attribute is used in various question types to determine how a
specific answer impacts the question's score. Specifically, for incorrect answers
in the multichoice
and truefalse
types, the value calculated by dividing
fraction
by the number of incorrect answers available is considered as the
amount deducted in case of an incorrect response.
A question_category
object.
Other question definition functions:
define_extended_question()
,
define_question()
,
define_questions_from_csv()
,
define_questions_from_data_frame()
,
define_questions_from_excel()
,
generate_xml()
,
generate_xml_file()
qc <- question_category(category = 'Initial test')
qc <- question_category(category = 'Initial test')
Reads a csv file of questions and returns a data frame.
read_question_csv(file, sep = ",")
read_question_csv(file, sep = ",")
file |
A string, name of a text file. |
sep |
Column separator character. |
A data frame.
Other support functions:
create_question_csv()
,
create_question_data_frame()
,
create_question_excel()
,
read_question_excel()
,
vector_to_string()
file <- system.file("extdata", "questions.csv", package = "moodef") df <- read_question_csv(file = file)
file <- system.file("extdata", "questions.csv", package = "moodef") df <- read_question_csv(file = file)
Reads an Excel file of questions and returns a data frame.
read_question_excel(file, sheet_index = NULL, sheet_name = NULL)
read_question_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_question_csv()
,
create_question_data_frame()
,
create_question_excel()
,
read_question_csv()
,
vector_to_string()
file <- system.file("extdata", "questions.xlsx", package = "moodef") df <- read_question_excel(file = file)
file <- system.file("extdata", "questions.xlsx", package = "moodef") df <- read_question_excel(file = file)
Insert the separator that we consider to later perform the reverse operation.
vector_to_string(vector)
vector_to_string(vector)
vector |
A vector of strings. |
A string.
Other support functions:
create_question_csv()
,
create_question_data_frame()
,
create_question_excel()
,
read_question_csv()
,
read_question_excel()
s <- vector_to_string(c('Addition', '+'))
s <- vector_to_string(c('Addition', '+'))