R/fill_grade_roster.R

Defines functions fill_grade_roster

Documented in fill_grade_roster

#' fill_grade_roster
#' 
#' Still need to open, check and save
#' 
#' @param IDs vector of IDs
#' @param total vector of marks - order corresponds to IDs
#' @param infile empty grade roster
#' @param outfile lace to save complete grade roster
#'
#' @return VOID
#' @export
#'
#' @examples
#' set.seed(2019)
#' df  <- tibble(
#'   ID = 1:7, 
#'   total = sample(80:100, 7)
#'   )
#'   df
#'   fill_grade_roster(df$ID, df$total, 
#'                infile = "inst/grade_example.csv", 
#'                outfile = "inst/example_output.csv")
fill_grade_roster  <- function(IDs, total, infile, outfile){
  # Read in the grade roster
  grade_roster  <- read_lines(infile)
  # Get header
  header  <- grade_roster[1:7]
  # Write out header
  write_lines(header, outfile)
  # data 
  n  <- length(grade_roster)
  data  <- grade_roster[8:n]  
  data  <- read_csv(data)
  # Add totals
  for(i in 1:nrow(data)){
    ID  <- data$EmplID[i]
    index  <- which(IDs == ID)
    if(length(index) > 0){
      data$`Mark/Grade Input`[i]  <- total[index]
    }
  }
  write_csv(data, outfile, append = TRUE, na = "", col_names = TRUE)
}
# set.seed(2019)
# df  <- tibble(
#   ID = 1:7, 
#   total = sample(80:100, 7)
# )
# df
# fill_grade_roster(df$ID, df$total, 
#                   infile = "inst/grade_example.csv", 
#                   outfile = "inst/example_output.csv")
jonotuke/examMarking documentation built on Nov. 26, 2019, 3:48 p.m.