R/count_fields.R

Defines functions counts_fields

Documented in counts_fields

#' Group_by and count the occurances of a group in a data set
#'
#' Group a dataset by a field and provide the counts of each group
#'
#' @description
#' This takes a tibble and a field name and does a group_by that field and
#' counts the results
#'
#' @param data The tibble to count groups
#' @param field_name The name of the field to group and count
#'
#' @export
#' @importFrom rlang enquo
#'
#' @examples
#' library(rolemapr)
#' library(tibble)
#'
#' practice_data <- tribble(
#'    ~practice_area, ~role,
#'    "Test area", "Test Role",
#'  )
#' counts_fields(practice_data, "practice_area")
#'
counts_fields <- function(data, field_name) {
  f <- enquo(field_name)
  data %>%
    dplyr::group_by(practice_area) %>%
    dplyr::count()
}
whjelmar/rolemapr documentation built on Aug. 8, 2022, 1:32 p.m.