Skip to contents

Clean Moodle Quiz report for easier manipulation in R. It extracts student ID from "Email address" column; unites "First name" and "Surname" column; converts dash ("-"), which can be presented when student not given answer, to NA; and forces "Grade" and "Q. x /x" to numeric value (if any of "Not yet graded", "Requires grading", or "-" is presented it will be NA).

Usage

clean_moodle(
  data,
  extract_id = TRUE,
  extract_id_from = c("Email address", "Institution", "Department", "ID number"),
  id_regex = ".*",
  sep_name = " ",
  dash_na = TRUE,
  force_numeric = TRUE
)

Arguments

data

A data.frame of Moodle Quiz report.

extract_id

(Logical) TRUE: An "ID" column will be created by extracting characters from "Email address" column using regular expression as id_regex. If FALSE: "Email address" column will be renamed to "Email".

extract_id_from

(Character) Choose column to extract ID from one of: "Email address", "Institution", "Department", and "ID number" (a custom one).

id_regex

(Character) Regular expression used to extract ID from "Email address". The default is ".*" meaning all characters. If your student email addresses has numeric IDs in them, try "[:digit:]+" to extract digits from the email. Note: Regular expression syntax is the same as stringr.

sep_name

(Character) A character in the new "Name" column that separate original "First name" and "Surname".

dash_na

(Logical) TRUE: format dash "-" in any columns to NA. If FALSE: leave dash "-" as is

force_numeric

(Logical) TRUE: force "Grade" and "Q. x /x" columns to numeric type (if any of "Not yet graded", "Requires grading", or "-" is presented it will be NA). If FALSE: leave "Grade" and "Q. x /x" columns as is.

Value

A data.frame with cleaner column names and better formatted data. Although the column names are cleaned, some metadata is lost such as maximum score of quiz and questions. Check out get_quiz_attr() for get these metadata.

Examples

clean_moodle(grades_ls$Quiz_1,
             id_regex = "[:digit:]+")
#> # A tibble: 26 × 15
#>    Name      ID    Insti…¹ Depar…² State Started             Grade…³    Q1    Q2
#>    <chr>     <chr> <lgl>   <lgl>   <chr> <dttm>                <dbl> <dbl> <dbl>
#>  1 Jada Roq… 017   NA      NA      Fini… 2021-06-02 08:28:00    9.47  0.26  0.26
#>  2 Ronin Ali 001   NA      NA      Fini… 2021-06-02 14:21:00    9.74  0.79  0.26
#>  3 Jerry Ho… 002   NA      NA      Fini… 2021-06-02 16:04:00    9.47  0.26  0.26
#>  4 Nathan B… 026   NA      NA      Fini… 2021-06-02 00:00:00   10     0.79  0.26
#>  5 Rohith H… 024   NA      NA      Fini… 2021-06-02 14:47:00   10     0.79  0.26
#>  6 Joy Ellis 013   NA      NA      Fini… 2021-06-02 03:56:00   10     0.79  0.26
#>  7 Jeremy N… 023   NA      NA      Fini… 2021-06-02 08:09:00    9.21  0.79  0.26
#>  8 Christop… 003   NA      NA      Fini… 2021-06-02 00:49:00    9.47  0.26  0.26
#>  9 Israel M… 018   NA      NA      Fini… 2021-06-02 15:36:00   10     0.79  0.26
#> 10 Zubaida … 022   NA      NA      Fini… 2021-06-02 23:11:00   10     0.79  0.26
#> # … with 16 more rows, 6 more variables: Q3 <dbl>, Q4 <dbl>, Q5 <dbl>,
#> #   Q6 <dbl>, Q7 <dbl>, Q8 <dbl>, and abbreviated variable names ¹​Institution,
#> #   ²​Department, ³​Grade_10.00