Package 'moodef'

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

Help Index


Create a question csv file

Description

Creates an empty question csv file.

Usage

create_question_csv(file, sep = ",")

Arguments

file

A string, name of a text file.

sep

Column separator character.

Value

A string.

See Also

Other support functions: create_question_data_frame(), create_question_excel(), read_question_csv(), read_question_excel(), vector_to_string()

Examples

file <- create_question_csv(file = tempfile(fileext = '.csv'))

Create a question data frame

Description

Creates an empty question data frame.

Usage

create_question_data_frame()

Value

A data frame.

See Also

Other support functions: create_question_csv(), create_question_excel(), read_question_csv(), read_question_excel(), vector_to_string()

Examples

df <- create_question_data_frame()

Create a question Excel file

Description

Creates an empty question Excel file.

Usage

create_question_excel(file)

Arguments

file

A string, name of a text file.

Value

A string.

See Also

Other support functions: create_question_csv(), create_question_data_frame(), read_question_csv(), read_question_excel(), vector_to_string()

Examples

file <- create_question_excel(file = tempfile(fileext = '.xlsx'))

Define question

Description

Define a question and the possible answers. The type of question is deduced.

Usage

define_question(qc, type, question, image, image_alt, answer, ...)

## S3 method for class 'question_category'
define_question(
  qc,
  type = "",
  question = "",
  image = "",
  image_alt = "",
  answer = "",
  ...
)

Arguments

qc

A question_category object.

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.

Details

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.

Value

A question_category.

See Also

Other question definition: define_questions_from_csv(), define_questions_from_data_frame(), define_questions_from_excel(), generate_xml(), generate_xml_file(), question_category()

Examples

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.'
  )

Define questions from a csv file

Description

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.

Usage

define_questions_from_csv(qc, file, sep)

## S3 method for class 'question_category'
define_questions_from_csv(qc, file, sep = ",")

Arguments

qc

A question_category object.

file

A string, name of a text file.

sep

Column separator character.

Details

For answers where a vector is required, "<|>" is used as a separator of the vector elements.

Value

A question_category.

See Also

Other question definition: define_question(), define_questions_from_data_frame(), define_questions_from_excel(), generate_xml(), generate_xml_file(), question_category()

Examples

file <- system.file("extdata", "questions.csv", package = "moodef")
qc <-
  question_category(category = 'Initial test', adapt_images = TRUE) |>
  define_questions_from_csv(file = file)

Define questions from a data frame

Description

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.

Usage

define_questions_from_data_frame(qc, df)

## S3 method for class 'question_category'
define_questions_from_data_frame(qc, df)

Arguments

qc

A question_category object.

df

A data frame.

Details

For answers where a vector is required, "<|>" is used as a separator of the vector elements.

Value

A question_category.

See Also

Other question definition: define_question(), define_questions_from_csv(), define_questions_from_excel(), generate_xml(), generate_xml_file(), question_category()

Examples

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)

Define questions from a Excel file

Description

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.

Usage

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)

Arguments

qc

A question_category object.

file

A string, name of an Excel file.

sheet_index

A number, sheet index in the workbook.

sheet_name

A string, sheet name.

Details

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.

Value

A question_category.

See Also

Other question definition: define_question(), define_questions_from_csv(), define_questions_from_data_frame(), generate_xml(), generate_xml_file(), question_category()

Examples

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

Description

Generate questions xml string

Usage

generate_xml(qc)

## S3 method for class 'question_category'
generate_xml(qc)

Arguments

qc

A question_category object.

Value

A string.

See Also

Other question definition: define_question(), define_questions_from_csv(), define_questions_from_data_frame(), define_questions_from_excel(), generate_xml_file(), question_category()

Examples

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

Description

Generate questions xml file

Usage

generate_xml_file(qc, file)

## S3 method for class 'question_category'
generate_xml_file(qc, file = NULL)

Arguments

qc

A question_category object.

file

A string, file name.

Value

A question_category.

See Also

Other question definition: define_question(), define_questions_from_csv(), define_questions_from_data_frame(), define_questions_from_excel(), generate_xml(), question_category()

Examples

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 class

Description

Creates a question_category object.

Usage

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
)

Arguments

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.

Details

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.

Value

A question_category object.

See Also

Other question definition: define_question(), define_questions_from_csv(), define_questions_from_data_frame(), define_questions_from_excel(), generate_xml(), generate_xml_file()

Examples

qc <- question_category(category = 'Initial test')

Read a question csv file

Description

Reads a csv file of questions and returns a data frame.

Usage

read_question_csv(file, sep = ",")

Arguments

file

A string, name of a text file.

sep

Column separator character.

Value

A data frame.

See Also

Other support functions: create_question_csv(), create_question_data_frame(), create_question_excel(), read_question_excel(), vector_to_string()

Examples

file <- system.file("extdata", "questions.csv", package = "moodef")
df <- read_question_csv(file = file)

Read a question Excel file

Description

Reads an Excel file of questions and returns a data frame.

Usage

read_question_excel(file, sheet_index = NULL, sheet_name = NULL)

Arguments

file

A string, name of a text file.

sheet_index

A number, sheet index in the workbook.

sheet_name

A string, sheet name.

Details

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.

Value

A data frame.

See Also

Other support functions: create_question_csv(), create_question_data_frame(), create_question_excel(), read_question_csv(), vector_to_string()

Examples

file <- system.file("extdata", "questions.xlsx", package = "moodef")
df <- read_question_excel(file = file)

Transforms a vector of strings into a string

Description

Insert the separator that we consider to later perform the reverse operation.

Usage

vector_to_string(vector)

Arguments

vector

A vector of strings.

Value

A string.

See Also

Other support functions: create_question_csv(), create_question_data_frame(), create_question_excel(), read_question_csv(), read_question_excel()

Examples

s <- vector_to_string(c('Addition', '+'))