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 questions 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.1.0 |
Built: | 2024-11-05 06:19:04 UTC |
Source: | CRAN |
Creates an empty question csv file.
create_question_csv(file, sep = ",")
create_question_csv(file, sep = ",")
file |
A string, name of a text file. |
sep |
Column separator character. |
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()
create_question_data_frame()
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)
create_question_excel(file)
file |
A string, name of a text file. |
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'))
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:
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:
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:
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:
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:
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:
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 )
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 )
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. |
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.
A question_category
object.
Other question definition:
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', '+'))