R/snhu-tidy-assignments.R

#' Tidy raw assignment data from SNHU
#'
#' Allows users to take raw SNHU assignment data and create a usable dataframe for analysis
#'
#' `snhu_tidy_assignments` allows users to take the raw SNHU assignment data and create a dataframe that has one row per student.
#' Each row will include every assignment included in the OVERALL data. This means that some students may have NA values for some
#' assignments. This is not a problem.
#'
#' @param file_name A character string. This is the name of the file within your current working directory that has the data you want.
#'  it needs to be a .csv file, NOT the original .xlsx file that SNHU sends.
#' @param course A character string. This is the name of the course that you want to include.
#' @param term A character string. This is the name of the term that you want to include.
#' @import tidyr
#' @import dplyr
#' @export

snhu_tidy_assignments <- function(file_name, course = "SCI-200", term = "17EW4"){

  requireNamespace("tidyr")
  requireNamespace("dplyr")

  read.csv(file_name, header = TRUE, sep = ",", quote = "\"", stringsAsFactors = FALSE) %>%
    select(one_of(c("COURSE", "TERM", "TITLE", "USER_PK1", "FINAL_GRADE"))) %>%
    dplyr::filter(COURSE == course, TERM == term) %>%
    spread(TITLE, FINAL_GRADE) %>%
    mutate(total_points = rowSums(.[4:ncol(.)], na.rm = TRUE)) %>%
    distinct()
}
plduffy/rsoomo documentation built on May 26, 2019, 12:32 a.m.