R/date_range_monthly.R

Defines functions format_month date_range_monthly

#' Create a range of monthly dates in the `yyyy-mm` format 
#'
#' @param
#' @keywords
#' @export
#' @example
#' format_month()
date_range_monthly <- function(.start, .end) {
  range_vector <- seq(.start, .end, by = "months")
  range_vector %>%
    map_chr(., ~ str_glue("{year(.x)}-{format_month(.x)}"))
}

format_month <- function(.x) {
  return(
    if_else(
      str_length(month(.x)) == 1, 
      paste("0", month(.x), sep = ""), 
      paste(month(.x))) 
  )
}
robertmitchellv/babblr documentation built on Nov. 23, 2018, 2:07 p.m.