R/var_labels.R

Defines functions var_labels

#' Get a data frame of variable names and labels from a dataset
#'
#' @param dset A data frame
#'
#' @return a data frame with three columns: variable names (vars), variable
#' labels (var_labels), and the number of missing values (num_missing)
#' @export
#'
#' @examples
#' vars_labels(iris)
var_labels <- function(dset){

  # Get the labels
  var_lables <-
    map(dset, ~ ifelse(is.null(attr(.x, "label")),
                       "None",
                       attr(.x, "label"))) %>%
    unlist()

  # Get the number of missing values
  num_missing <-
    map(dset, ~ sum(is.na(.x))) %>%
    unlist()

  # get the variable names
  vars <- names(dset)

  data_frame(vars=vars, var_lables = var_lables, num_missing = num_missing)
}
FredHutch/sasHelpers documentation built on May 3, 2019, 3:32 p.m.