#' 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))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.