R/general_tools.R

#' @title Item Responses Re-shaper
#'
#' @description Formats Responses from long to wide
#'
#' @details
#' Transposes a CRM-downloaded Test Responses dataframe from long to wide.
#'
#' @param responses The test responses dataframe (see import.responses)
#' @return A wide responses dataframe
#' @examples tools.wideresponses(ResponseImport)
#' @family Tools
tools.wideresponses <- function(responses){
  return(reshape(responses, idvar = "ClientCandidateId", timevar= "ItemName", direction = "wide"))
}

#' @title Item List Creator
#'
#' @description Creates list of Item Names from Responses.
#'
#' @details
#' Creates a list of unique Item Id's from a CRM-downloaded Response table.
#'
#' @param responses The test responses dataframe (see import.responses)
#' @return A list of Item Id's in responses
#' @examples tools.itemlist(ResponseImport)
#' @family Tools
tools.itemlist <- function(responses){
  return(unique(responses$ItemName))
}

#' @title Item List Creator w/ Volume
#'
#' @description Creates list of Item Names from Responses with count of appearances.
#'
#' @details
#' Creates a list of unique Item Id's from a CRM-downloaded Response table,
#' with a count of how many times each shows up.
#'
#' @param responses The test responses dataframe (see import.responses)
#' @return A list of Item Id's in responses
#' @examples tools.itemlist.volume(ResponseImport)
#' @family Tools
tools.itemlist.volume <- function(responses){
  responses$count <- 1
  return(aggregate(responses$ItemName, responses$count, FUN = sum))
}
m070ch/ips.tools documentation built on May 18, 2019, 8:09 p.m.