R/draw_a_name.R

Defines functions draw_a_name

Documented in draw_a_name

#' draw_a_name
#'
#' Draw graph for a given name based on the prenoms data
#' @param the_name Person name to be graphed
#' @param the_sex Gender of the name
#' @return graph for queried parameters
#' @import assertthat
#' @import dplyr
#' @import tidyr
#' @import dygraphs
#' @import prenoms
#' @examples
#' draw_a_name("Dana", "F")
#' @export

draw_a_name <- function(the_name, the_sex) {
  assert_that(is.character(the_name))
  assert_that(the_sex == "F" || the_sex == "M")

  prenoms %>%
    group_by(year,name,sex) %>%
    summarise(total = sum(n)) %>%
    filter(name == the_name, sex == the_sex) %>%
    spread(key = name, value = total) %>%
    dygraph()
}
megahf/megahhomework documentation built on May 29, 2019, 4:42 a.m.