#' Change class
#'
#' Changes the class of a text timestamp to a POSIXct.
#'
#' @param df A data frame or tibble.
#' @param x A column with datetime in text format.
#'
#' @return The same data frame with the timestamp column as datetime.
#' @export
#'
#' @examples
#' dog_date_from_text(tibble::tibble(time_text = as.character(Sys.time())), time_text)
dog_date_from_text <- function(df, x){
x <- rlang::enquo(x)
name <- rlang::quo_name(x)
if(any(class(df[[name]]) %in% c("POSIXct", "POSIXt" ))) {
return(df)
}
else if (class(df[[name]]) == "character") {
df <- dplyr::mutate(df, !!name := lubridate::ymd_hms(!!x))
return(df)
}
else {
stop("check class of column manually")
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.