R/dates.R

Defines functions date_standard_cols

#' Add helpful date columns.
#'
#' @param .df a data frame.
#' @param .date_col the name of the date column unqouted.
#' @return an updated version of the data frame supplied to
#'  .df with four additional date related columns:
#'   1) datetime, 2) date, 3) year, and 4) month.
#' @export

date_standard_cols <- function(.df, .date_col) {
  .date_col <- rlang::enquo(.date_col)

  .df %>%
    dplyr::mutate(datetime = lubridate::as_datetime(!!.date_col, tz = "America/New_York"),
                  date = lubridate::as_date(!!.date_col, tz = "America/New_York"),
                  year = lubridate::year(date),
                  month = lubridate::month(date, label = TRUE, abbr = FALSE))
}
BWAM/wqs documentation built on March 24, 2020, 5:26 p.m.