R/add_date.R

Defines functions add_date

Documented in add_date

#' Turn created_at field into a date variable 
#'
#' @param df A parsed Tweet JSON file (data.frame) which includes created_at variable 
#'
#' @return date column is added to the data.frame
#' 
#' @importFrom stringr word 
#' @importFrom magrittr "%>%"
#' @importFrom dplyr mutate
#' @export

add_date <- function(df){
    
    # Parse create_at variable 
    
    df$date <- as.POSIXct(df[["created_at"]], 
                            tz = "UTC",
                            format = "%a %b %d %H:%M:%S %z %Y") %>% #
               word(1) # Only year month date 
    
    # Output 
    
    df 
}
jaeyk/tidytweetjson documentation built on June 24, 2024, 10:56 p.m.