R/to_case_when_block.R

Defines functions to_case_when_block

Documented in to_case_when_block

#' Build case_when block for a mutate()
#'
#' @param uniqvals unique values of varname 
#' @param varname variable name for the LHS of the case_when block
#'
#' @return prints R code to the console that can be copy and pasted
#' @export
to_case_when_block <- function(uniqvals,varname) {
  
  # to_case_when_block(c('x','y','z'),'X')
  cat(paste0(
    'case_when(\n',paste0(paste0('  ',varname , " == '",uniqvals, "' ~ ''"), collapse = ',\n'),'\n)'))
  
}
rdisalv2/dismisc documentation built on Nov. 2, 2021, 1:34 a.m.