R/force_categorical.r

#' @title force_categorical
#'
#' @description changes variables to be labeled as categorical
#' 
#' @export
#'
#' @param variables a \code{\link[tibble]{tibble}} generated by \code{\link[mndredge]{identify_variables}}
#' @param columns the columns to update
#' @return the updated \code{\link[tibble]{tibble}}
#'
#' @author Mark Newman, \email{mark@trinetteandmark.com}
#' @keywords utilities
#' @family utilities
#'
#' @examples
#'   \dontshow{
#'     library(magrittr)
#'     library(mndredge) }
#'   data.frame(
#'     a = 1:10,
#'     b = 1:10) %>%
#'     identify_variables() %>%
#'     force_categorical("b")
#'
force_categorical <- function(variables, columns) {
  
  stopifnot(
    variables %>% is.tibble(),
    columns %>% is.vector())
  
  variables[variables$name %in% columns,]$type <- "categorical"
  
  variables
}
markanewman/mndredge documentation built on May 9, 2019, 5:52 a.m.