diff --git a/R/create_chatlog.R b/R/create_chatlog.R index d307525..b69bd2b 100644 --- a/R/create_chatlog.R +++ b/R/create_chatlog.R @@ -13,8 +13,8 @@ #' @param n_diff_smilies Number of different smilies that are used in the simulated chat. #' @param n_media Number of messages that contain omitted media files. Must be smaller or equal to n_messages. #' @param n_sdp Number of messages that contain self-deleting photos. Must be smaller or equal to n_messages. -#' @param startdate Earliest possible date for messages. Format is 'dd.mm.yyyy'. Timestamps for messages are created automatically between startdate and enddate. -#' @param enddate Latest possible date for messages. Format is 'dd.mm.yyyy'. Timestamps for messages are created automatically between startdate and enddate. +#' @param startdate Earliest possible date for messages. Format is 'dd.mm.yyyy'. Timestamps for messages are created automatically between startdate and enddate. Input is interpreted as UTC +#' @param enddate Latest possible date for messages. Format is 'dd.mm.yyyy'. Timestamps for messages are created automatically between startdate and enddate. Input is interpreted as UTC #' @param language Parameter for the language setting of the exporting phone. Influences structure of system messages #' @param time_format Parameter for the time format setting of the exporting phone (am/pm vs. 24h). Influences the structure of timestamps. #' @param os Parameter for the operating system setting of the exporting phone. Influences the structure of timestamps and WhatsApp system messages. @@ -87,20 +87,20 @@ create_chatlog <- function(n_messages = 150, } # validating startdate - startdate_check <- try(as.Date(startdate, format = "%d.%m.%Y")) + startdate_check <- try(as.Date(startdate, format = "%d.%m.%Y", tz = "UTC")) if ("try-error" %in% class(startdate_check) || is.na(startdate_check)) { print("Variable 'startdate' musst be a character string of format dd.mm.YYYY") } # validating enddate - enddate_check <- try(as.Date(enddate, format = "%d.%m.%Y")) + enddate_check <- try(as.Date(enddate, format = "%d.%m.%Y", tz = "UTC")) if ("try-error" %in% class(enddate_check) || is.na(enddate_check)) { print("Variable 'enddate' musst be a character string of format dd.mm.YYYY") } # validate that startdate is before enddate - sDate <- as.POSIXct(as.Date(startdate, format = "%d.%m.%Y")) - eDate <- as.POSIXct(as.Date(enddate, format = "%d.%m.%Y")) + sDate <- as.POSIXct(as.Date(startdate, format = "%d.%m.%Y", tz = "UTC"), tz = "UTC") + eDate <- as.POSIXct(as.Date(enddate, format = "%d.%m.%Y", tz = "UTC"), tz = "UTC") if (sDate >= eDate) { warning("starting date must be earlier than ending date.") @@ -172,8 +172,8 @@ create_chatlog <- function(n_messages = 150, # Timestamp function (taken from: https://stackoverflow.com/questions/42021394/random-incremental-timestamp-in-r) RandomTimeStamp <- function(M, sDate = startdate, eDate = enddate) { - sDate <- as.POSIXct(as.Date(sDate, format = "%d.%m.%Y")) - eDate <- as.POSIXct(as.Date(eDate, format = "%d.%m.%Y")) + sDate <- as.POSIXct(as.Date(sDate, format = "%d.%m.%Y", tz = "UTC"), tz = "UTC") + eDate <- as.POSIXct(as.Date(eDate, format = "%d.%m.%Y", tz = "UTC"), tz = "UTC") dTime <- as.numeric(difftime(eDate, sDate, units = "sec")) sTimeStamp <- sort(runif(M, 0, dTime)) TimeStamp <- sDate + sTimeStamp @@ -188,29 +188,29 @@ create_chatlog <- function(n_messages = 150, if (language == "german") { if (os == "android") { if (time_format == "24h") { - ts <- strftime(ts, format = "%d.%m.%y, %H:%M - ") + ts <- strftime(ts, format = "%d.%m.%y, %H:%M - ", tz = "UTC") } else { - ts <- strftime(ts, format = "%d.%m.%y, %I:%M %p - ") + ts <- strftime(ts, format = "%d.%m.%y, %I:%M %p - ", tz = "UTC") } } else { if (time_format == "24h") { - ts <- strftime(ts, format = "[%d.%m.%y, %H:%M:%S] ") + ts <- strftime(ts, format = "[%d.%m.%y, %H:%M:%S] ", tz = "UTC") } else { - ts <- strftime(ts, format = "[%m/%d/%y, %I:%M:%S %p] ") + ts <- strftime(ts, format = "[%m/%d/%y, %I:%M:%S %p] ", tz = "UTC") } } } else { if (os == "android") { if (time_format == "24h") { - ts <- strftime(ts, format = "%m/%d/%y, %H:%M - ") + ts <- strftime(ts, format = "%m/%d/%y, %H:%M - ", tz = "UTC") } else { - ts <- strftime(ts, format = "%m/%d/%y, %I:%M %p - ") + ts <- strftime(ts, format = "%m/%d/%y, %I:%M %p - ", tz = "UTC") } } else { if (time_format == "24h") { - ts <- strftime(ts, format = "[%m/%d/%y, %H:%M:%S] ") + ts <- strftime(ts, format = "[%m/%d/%y, %H:%M:%S] ", tz = "UTC") } else { - ts <- strftime(ts, format = "[%m/%d/%y, %I:%M:%S %p] ") + ts <- strftime(ts, format = "[%m/%d/%y, %I:%M:%S %p] ", tz = "UTC") } } } diff --git a/R/plot_emoji.R b/R/plot_emoji.R index 4c03d2f..e433b1b 100644 --- a/R/plot_emoji.R +++ b/R/plot_emoji.R @@ -2,8 +2,8 @@ #' @description Plots four different types of graphs for the emoji contained in a parsed WhatsApp chat log. Returns dataframe used for plotting if desired. #' @param data A WhatsApp chat log that was parsed with \code{\link[WhatsR]{parse_chat}}. #' @param names A vector of author names that the plots will be restricted to. -#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". -#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". +#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. +#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. #' @param min_occur Minimum number of occurrences for emoji to be included in the plots. Default is 1. #' @param return_data If TRUE, returns the subsetted data frame used for plotting. Default is FALSE. #' @param emoji_vec A vector of emoji that the visualizations and data will be restricted to. @@ -29,7 +29,7 @@ plot_emoji <- function(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(),tz = "UTC")), min_occur = 1, return_data = FALSE, emoji_vec = "all", @@ -43,10 +43,14 @@ plot_emoji <- function(data, Date <- Sender <- day <- hour <- `Number of Emoji` <- ave <- total <- Var1 <- Freq <- n <- emoji <- Emoji <- Glyph <- NULL # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # start- and endtime are convertable to POSIXct - if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.") + if (is.character(starttime) == FALSE | is.na(anytime(starttime, asUTC=TRUE,tz="UTC"))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (is.character(endtime) == FALSE | is.na(anytime(endtime, asUTC=TRUE,tz="UTC"))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (anytime(starttime, asUTC=TRUE,tz="UTC") >= anytime(endtime, asUTC=TRUE,tz="UTC")) stop("starttime has to be before endtime.") # min_occur needs to be 1 or bigger if (min_occur < 1) stop("Please provide a min_occur of >= 1.") @@ -70,17 +74,17 @@ plot_emoji <- function(data, Dictionary <- read.csv(system.file("EmojiDictionary.csv", package = "WhatsR")) # setting starttime - if (starttime == anytime("1960-01-01 00:00")) { - starttime <- min(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(starttime, asUTC=TRUE,tz="UTC") <= min(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + starttime <- min(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - starttime <- anytime(starttime, asUTC = TRUE) + starttime <- anytime(starttime, asUTC=TRUE,tz="UTC") } # setting endtime - if (difftime(Sys.time(), endtime, units = "min") < 1) { - endtime <- max(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(endtime, asUTC=TRUE,tz="UTC") >= max(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + endtime <- max(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - endtime <- anytime(endtime, asUTC = TRUE) + endtime <- anytime(endtime, asUTC=TRUE,tz="UTC") } # setting names argument @@ -140,16 +144,17 @@ plot_emoji <- function(data, } - NewDates <- as.POSIXct(unlist(NewDates),origin = '1970-01-01') + NewDates <- as.POSIXct(unlist(NewDates),origin = '1970-01-01', tz="UTC") # pasting together options(stringsAsFactors = FALSE) NewFrame <- cbind.data.frame(NewDates,NewSender,NewEmoji) # creating time data - NewFrame$hour <- as.POSIXlt(NewFrame$NewDates)$hour - NewFrame$year <- as.POSIXlt(NewFrame$NewDates)$year + 1900 - NewFrame$day <- weekdays(as.POSIXlt(NewFrame$NewDates), abbreviate = FALSE) + # TODO: Maybe this is where it goes wrong? + NewFrame$hour <- as.POSIXlt(NewFrame$NewDates,tz = "UTC")$hour + NewFrame$year <- as.POSIXlt(NewFrame$NewDates,tz = "UTC")$year + 1900 + NewFrame$day <- weekdays(as.POSIXlt(NewFrame$NewDates,tz = "UTC"), abbreviate = FALSE) # setting correct emoji_vec if (length(emoji_vec) == 1 && emoji_vec == "all") { @@ -180,7 +185,7 @@ plot_emoji <- function(data, # factor ordering weekdays <- rev(c("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")) - # transalte to english for better compatibility + # translate to english for better compatibility helperframe2$day <- mgsub(helperframe2$day, pattern = c("Sonntag","Samstag","Freitag","Donnerstag","Mittwoch","Dienstag","Montag"), replacement = weekdays) diff --git a/R/plot_lexical_dispersion.R b/R/plot_lexical_dispersion.R index f72a044..fff9786 100644 --- a/R/plot_lexical_dispersion.R +++ b/R/plot_lexical_dispersion.R @@ -2,8 +2,8 @@ #' @description Visualizes the occurrence of specific keywords within the chat. Requires the raw message content to be contained in the preprocessed data #' @param data A WhatsApp chatlog that was parsed with \code{\link[WhatsR]{parse_chat}} using anonimize = FALSE or anonimize = "add". #' @param names A vector of author names that the plots will be restricted to. -#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". -#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". +#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. +#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. #' @param keywords A vector of keywords to be displayed, default is c("hello","world"). #' @param return_data Default is FALSE, returns data frame used for plotting when TRUE. #' @param exclude_sm If TRUE, excludes the WhatsApp System Messages from the descriptive statistics. Default is FALSE. @@ -23,17 +23,21 @@ plot_lexical_dispersion <- function(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(),tz = "UTC")), keywords = c("hello", "world"), return_data = FALSE, exclude_sm = FALSE, ...) { # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # start- and endtime are convertable to POSIXct - if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.") + if (is.character(starttime) == FALSE | is.na(anytime(starttime, asUTC=TRUE,tz="UTC"))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (is.character(endtime) == FALSE | is.na(anytime(endtime, asUTC=TRUE,tz="UTC"))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (anytime(starttime, asUTC=TRUE,tz="UTC") >= anytime(endtime, asUTC=TRUE,tz="UTC")) stop("starttime has to be before endtime.") # Mesage column must be contained if (!is.character(data$Flat)) {stop("'data' must contain a character column named 'Message'")} @@ -58,17 +62,17 @@ plot_lexical_dispersion <- function(data, keywords <- tolower(keywords) # setting starttime - if (starttime == anytime("1960-01-01 00:00")) { - starttime <- min(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(starttime, asUTC=TRUE,tz="UTC") <= min(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + starttime <- min(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - starttime <- anytime(starttime, asUTC = TRUE) + starttime <- anytime(starttime, asUTC=TRUE,tz="UTC") } # setting endtime - if (difftime(Sys.time(), endtime, units = "min") < 1) { - endtime <- max(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(endtime, asUTC=TRUE,tz="UTC") >= max(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + endtime <- max(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - endtime <- anytime(endtime, asUTC = TRUE) + endtime <- anytime(endtime, asUTC=TRUE,tz="UTC") } # setting names argument diff --git a/R/plot_links.R b/R/plot_links.R index acc800e..715b982 100644 --- a/R/plot_links.R +++ b/R/plot_links.R @@ -2,8 +2,8 @@ #' @description Visualizes the occurrence of links in a WhatsApp chatlog #' @param data A WhatsApp chatlog that was parsed with \code{\link[WhatsR]{parse_chat}}. #' @param names A vector of author names that the plots will be restricted to. -#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". -#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". +#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. +#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. #' @param use_domains If TRUE, links are shortened to domains. This includes the inputs in link_vec. Default is TRUE. #' @param exclude_long Either NA or a numeric value. If numeric value is provided, removes all links/domains longer than x characters. Default is 50. #' @param min_occur The minimum number of occurrences a link has to have to be included in the visualization. Default is 1. @@ -28,7 +28,7 @@ plot_links <- function(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(),tz = "UTC")), use_domains = TRUE, exclude_long = 50, min_occur = 1, @@ -41,10 +41,14 @@ plot_links <- function(data, Date <- Sender <- Links <- URL <- day <- hour <- n <- `Number of Links` <- ave <- total <- Var1 <- Freq <- NULL # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # start- and endtime are convertable to POSIXct - if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.") + if (is.character(starttime) == FALSE | is.na(anytime(starttime, asUTC=TRUE,tz="UTC"))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (is.character(endtime) == FALSE | is.na(anytime(endtime, asUTC=TRUE,tz="UTC"))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (anytime(starttime, asUTC=TRUE,tz="UTC") >= anytime(endtime, asUTC=TRUE,tz="UTC")) stop("starttime has to be before endtime.") # min_occur must be >= 1 if (min_occur < 1) stop("Please provide a min_occur of >= 1.") @@ -89,17 +93,17 @@ plot_links <- function(data, options(dplyr.summarise.inform = FALSE) # setting starttime - if (starttime == anytime("1960-01-01 00:00")) { - starttime <- min(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(starttime, asUTC=TRUE,tz="UTC") <= min(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + starttime <- min(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - starttime <- anytime(starttime, asUTC = TRUE) + starttime <- anytime(starttime, asUTC=TRUE,tz="UTC") } # setting endtime - if (difftime(Sys.time(), endtime, units = "min") < 1) { - endtime <- max(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(endtime, asUTC=TRUE,tz="UTC") >= max(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + endtime <- max(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - endtime <- anytime(endtime, asUTC = TRUE) + endtime <- anytime(endtime, asUTC=TRUE,tz="UTC") } # setting names argument @@ -151,7 +155,7 @@ plot_links <- function(data, NewDates[[i]] <- rep(data$DateTime[i], NoElements[i]) } - NewDates <- as.POSIXct(unlist(NewDates), origin = "1970-01-01") + NewDates <- as.POSIXct(unlist(NewDates), origin = "1970-01-01",tz = "UTC") # shorten URLs to domain if (use_domains == TRUE) { @@ -166,9 +170,9 @@ plot_links <- function(data, NewFrame <- cbind.data.frame(NewDates, NewSender, NewUrls) # creating time data - NewFrame$hour <- as.POSIXlt(NewFrame$NewDates)$hour - NewFrame$year <- as.POSIXlt(NewFrame$NewDates)$year + 1900 - NewFrame$day <- weekdays(as.POSIXlt(NewFrame$NewDates), abbreviate = FALSE) + NewFrame$hour <- as.POSIXlt(NewFrame$NewDates,tz = "UTC")$hour + NewFrame$year <- as.POSIXlt(NewFrame$NewDates,tz = "UTC")$year + 1900 + NewFrame$day <- weekdays(as.POSIXlt(NewFrame$NewDates,tz = "UTC"), abbreviate = FALSE) # setting correct link_vec if (length(link_vec) == 1 && link_vec == "all") { diff --git a/R/plot_locations.R b/R/plot_locations.R index d876008..2380ed9 100644 --- a/R/plot_locations.R +++ b/R/plot_locations.R @@ -2,8 +2,8 @@ #' @description Plots the location data that is sent in the WhatsApp chatlog on an auto-scaled map. Requires unanonimized 'Location' column in data #' @param data A WhatsApp chatlog that was parsed with \code{\link[WhatsR]{parse_chat}}with anonimize= FALSE or anonimize = "add". #' @param names A vector of author names that the plots will be restricted to. -#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". -#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". +#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. +#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. #' @param mapzoom Value for zoom into the map passed down to \code{\link[ggmap]{get_map}}. Default value is 5. Higher zoom will auto-download more map files which can take a while. #' @param return_data If TRUE, returns a data frame of LatLon coordinates extracted from the chat for more elaborate plotting. Default is FALSE. #' @param jitter_value Amount of random jitter to add to the geolocations to hide exact locations. Default value is 0.01. Can be NA for exact locations. @@ -30,7 +30,7 @@ plot_locations <- function(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(),tz = "UTC")), mapzoom = 5, return_data = FALSE, jitter_value = 0.01, @@ -44,10 +44,14 @@ plot_locations <- function(data, Lon <- Lat <- Sender <- NULL # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # start- and endtime are convertable to POSIXct - if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.") + if (is.character(starttime) == FALSE | is.na(anytime(starttime, asUTC=TRUE,tz="UTC"))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (is.character(endtime) == FALSE | is.na(anytime(endtime, asUTC=TRUE,tz="UTC"))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (anytime(starttime, asUTC=TRUE,tz="UTC") >= anytime(endtime, asUTC=TRUE,tz="UTC")) stop("starttime has to be before endtime.") # jitter_value checks if (!(is.numeric(jitter_value) | is.na(jitter_value))) {stop("jitter_value must be either NA for exact location or a numeric value > 0")} @@ -60,17 +64,17 @@ plot_locations <- function(data, if (!is.logical(exclude_sm)) stop("exclude_sm has to be either TRUE or FALSE.") # setting starttime - if (starttime == anytime("1960-01-01 00:00")) { - starttime <- min(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(starttime, asUTC=TRUE,tz="UTC") <= min(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + starttime <- min(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - starttime <- anytime(starttime, asUTC = TRUE) + starttime <- anytime(starttime, asUTC=TRUE,tz="UTC") } # setting endtime - if (difftime(Sys.time(), endtime, units = "min") < 1) { - endtime <- max(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(endtime, asUTC=TRUE,tz="UTC") >= max(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + endtime <- max(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - endtime <- anytime(endtime, asUTC = TRUE) + endtime <- anytime(endtime, asUTC=TRUE,tz="UTC") } # setting names argument diff --git a/R/plot_media.R b/R/plot_media.R index 26f87c8..7525187 100644 --- a/R/plot_media.R +++ b/R/plot_media.R @@ -2,8 +2,8 @@ #' @description Creates summary data frames or visualizations of sent media files or file types #' @param data A WhatsApp chatlog that was parsed with \code{\link[WhatsR]{parse_chat}} and was exported usng the "with media" option. #' @param names A vector of author names that the plots will be restricted to. -#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". -#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". +#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. +#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. #' @param use_filetype If TRUE, shortens sent file attachments to file types. #' @param min_occur The minimum number of occurrences a media (type) has to have to be included in the visualization. Default is 1. #' @param return_data If TRUE, returns the subset data frame. Default is FALSE. @@ -27,7 +27,7 @@ plot_media <- function(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(),tz = "UTC")), use_filetype = TRUE, min_occur = 1, return_data = FALSE, @@ -48,10 +48,14 @@ plot_media <- function(data, } # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # start- and endtime are convertable to POSIXct - if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.") + if (is.character(starttime) == FALSE | is.na(anytime(starttime, asUTC=TRUE,tz="UTC"))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (is.character(endtime) == FALSE | is.na(anytime(endtime, asUTC=TRUE,tz="UTC"))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (anytime(starttime, asUTC=TRUE,tz="UTC") >= anytime(endtime, asUTC=TRUE,tz="UTC")) stop("starttime has to be before endtime.") # min_occur must be >= 1 if (min_occur < 1) stop("Please provide a min_occur of >= 1.") @@ -72,17 +76,17 @@ plot_media <- function(data, if (!is.logical(use_filetype)) stop("use_filetype has to be either TRUE or FALSE.") # setting starttime - if (starttime == anytime("1960-01-01 00:00")) { - starttime <- min(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(starttime, asUTC=TRUE,tz="UTC") <= min(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + starttime <- min(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - starttime <- anytime(starttime, asUTC = TRUE) + starttime <- anytime(starttime, asUTC=TRUE,tz="UTC") } # setting endtime - if (difftime(Sys.time(), endtime, units = "min") < 1) { - endtime <- max(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(endtime, asUTC=TRUE,tz="UTC") >= max(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + endtime <- max(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - endtime <- anytime(endtime, asUTC = TRUE) + endtime <- anytime(endtime, asUTC=TRUE,tz="UTC") } # setting names argument @@ -133,16 +137,16 @@ plot_media <- function(data, NewDates[[i]] <- rep(data$DateTime[i], NoElements[i]) } - NewDates <- as.POSIXct(unlist(NewDates), origin = "1970-01-01") + NewDates <- as.POSIXct(unlist(NewDates), origin = "1970-01-01",tz="UTC") # pasting together options(stringsAsFactors = FALSE) NewFrame <- cbind.data.frame(NewDates, NewSender, NewMedia) # creating time data - NewFrame$hour <- as.POSIXlt(NewFrame$NewDates)$hour - NewFrame$year <- as.POSIXlt(NewFrame$NewDates)$year + 1900 - NewFrame$day <- weekdays(as.POSIXlt(NewFrame$NewDates), abbreviate = FALSE) + NewFrame$hour <- as.POSIXlt(NewFrame$NewDates,tz = "UTC")$hour + NewFrame$year <- as.POSIXlt(NewFrame$NewDates,tz = "UTC")$year + 1900 + NewFrame$day <- weekdays(as.POSIXlt(NewFrame$NewDates,tz = "UTC"), abbreviate = FALSE) # setting correct media_vec if (length(media_vec) == 1 && media_vec == "all") { diff --git a/R/plot_messages.R b/R/plot_messages.R index 8f93f2d..638736f 100644 --- a/R/plot_messages.R +++ b/R/plot_messages.R @@ -2,8 +2,8 @@ #' @description Plots summarizing the amount of messages per person #' @param data A WhatsApp chat log that was parsed with \code{\link[WhatsR]{parse_chat}}. #' @param names A vector of author names that the plots will be restricted to. -#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". -#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". +#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. +#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. #' @param plot Type of plot to be returned, options are "bar", "cumsum", "heatmap" and "pie". Default is "bar". #' @param return_data If TRUE, returns the subset data frame. Default is FALSE. #' @param exclude_sm If TRUE, excludes the WhatsApp system messages from the descriptive statistics. Default is FALSE. @@ -24,7 +24,7 @@ plot_messages <- function(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(),tz = "UTC")), plot = "bar", return_data = FALSE, exclude_sm = FALSE) { @@ -33,10 +33,14 @@ plot_messages <- function(data, Var1 <- Freq <- DateTime <- total <- Sender <- day <- hour <- `Number of Messages` <- NULL # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # start- and endtime are convertable to POSIXct - if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.") + if (is.character(starttime) == FALSE | is.na(anytime(starttime, asUTC=TRUE,tz="UTC"))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (is.character(endtime) == FALSE | is.na(anytime(endtime, asUTC=TRUE,tz="UTC"))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (anytime(starttime, asUTC=TRUE,tz="UTC") >= anytime(endtime, asUTC=TRUE,tz="UTC")) stop("starttime has to be before endtime.") # return_data must be bool if (!is.logical(return_data)) stop("return_data has to be either TRUE or FALSE.") @@ -48,17 +52,17 @@ plot_messages <- function(data, if (!is.logical(exclude_sm)) stop("exclude_sm has to be either TRUE or FALSE.") # setting starttime - if (starttime == anytime("1960-01-01 00:00")) { - starttime <- min(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(starttime, asUTC=TRUE,tz="UTC") <= min(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + starttime <- min(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - starttime <- anytime(starttime, asUTC = TRUE) + starttime <- anytime(starttime, asUTC=TRUE,tz="UTC") } # setting endtime - if (difftime(Sys.time(), endtime, units = "min") < 1) { - endtime <- max(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(endtime, asUTC=TRUE,tz="UTC") >= max(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + endtime <- max(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - endtime <- anytime(endtime, asUTC = TRUE) + endtime <- anytime(endtime, asUTC=TRUE,tz="UTC") } # setting names argument @@ -152,9 +156,9 @@ plot_messages <- function(data, # creating time data data <- cbind(data, MessageCount = rep(1, dim(data)[1])) NewFrame <- data[, c("DateTime", "Sender", "MessageCount")] - NewFrame$hour <- as.POSIXlt(NewFrame$DateTime)$hour - NewFrame$year <- as.POSIXlt(NewFrame$DateTime)$year + 1900 - NewFrame$day <- weekdays(as.POSIXlt(NewFrame$DateTime), abbreviate = FALSE) + NewFrame$hour <- as.POSIXlt(NewFrame$DateTime,tz="UTC")$hour + NewFrame$year <- as.POSIXlt(NewFrame$DateTime,tz="UTC")$year + 1900 + NewFrame$day <- weekdays(as.POSIXlt(NewFrame$DateTime,tz="UTC"), abbreviate = FALSE) # shaping dataframe helperframe2 <- NewFrame %>% diff --git a/R/plot_network.R b/R/plot_network.R index c2616ec..5854381 100644 --- a/R/plot_network.R +++ b/R/plot_network.R @@ -2,8 +2,8 @@ #' @description Plots a network for replies between authors in chat logs. Each message is evaluated as a reply to the previous one. #' @param data A WhatsApp chatlog that was parsed with \code{\link[WhatsR]{parse_chat}}. #' @param names A vector of author names that the visualization will be restricted to. Non-listed authors will be removed. -#' @param starttime Datetime that is used as the minimum boundary for exclusion. Input is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". -#' @param endtime Datetime that is used as the maximum boundary for exclusion. Input is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". +#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. +#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. #' @param return_data If TRUE, returns a data frame of subsequent interactions with senders and recipients. Default is FALSE. #' @param collapse_sessions Whether multiple subsequent messages by the same sender should be collapsed into one row. Default is FALSE. #' @param edgetype What type of content is displayed as an edge. Must be one of "TokCount","EmojiCount","SmilieCount","LocationCount","URLCount","MediaCount" or "n". @@ -26,7 +26,7 @@ plot_network <- function(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(),tz = "UTC")), return_data = FALSE, collapse_sessions = FALSE, edgetype = "n", @@ -36,10 +36,14 @@ plot_network <- function(data, mutate <- trials <- start <- streak_id <- ungroup <- `draw_network` <- `.` <- `get_streaks` <- `%v%<-` <- `lagged` <- `lag` <- NULL # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # start- and endtime are convertable to POSIXct - if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.") + if (is.character(starttime) == FALSE | is.na(anytime(starttime, asUTC=TRUE,tz="UTC"))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (is.character(endtime) == FALSE | is.na(anytime(endtime, asUTC=TRUE,tz="UTC"))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (anytime(starttime, asUTC=TRUE,tz="UTC") >= anytime(endtime, asUTC=TRUE,tz="UTC")) stop("starttime has to be before endtime.") # return_data must be bool if (!is.logical(return_data)) stop("return_data has to be either TRUE or FALSE.") @@ -54,17 +58,17 @@ plot_network <- function(data, if (!is.logical(exclude_sm)) stop("exclude_sm has to be either TRUE or FALSE.") # setting starttime - if (starttime == anytime("1960-01-01 00:00")) { - starttime <- min(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(starttime, asUTC=TRUE,tz="UTC") <= min(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + starttime <- min(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - starttime <- anytime(starttime, asUTC = TRUE) + starttime <- anytime(starttime, asUTC=TRUE,tz="UTC") } # setting endtime - if (difftime(Sys.time(), endtime, units = "min") < 1) { - endtime <- max(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(endtime, asUTC=TRUE,tz="UTC") >= max(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + endtime <- max(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - endtime <- anytime(endtime, asUTC = TRUE) + endtime <- anytime(endtime, asUTC=TRUE,tz="UTC") } # setting names argument @@ -155,10 +159,10 @@ plot_network <- function(data, # computing aggregate counts of tokens, smilies, emoji etc - # taken form: https://www.r-bloggers.com/2020/06/detecting-streaks-in-r/ + # source: https://www.r-bloggers.com/2020/06/detecting-streaks-in-r/ get_streaks <- function(vec) { x <- data.frame(trials = vec) - x <- x %>% mutate(lagged = lag(trials)) %>% # note: that's dplyr::lag, not stats::lag + x <- x %>% mutate(lagged = lag(trials)) %>% mutate(start = (trials != lagged)) x[1, "start"] <- TRUE x <- x %>% mutate(streak_id = cumsum(start)) @@ -246,6 +250,7 @@ plot_network <- function(data, # combining into dataset # TODO: Error in `data.frame(..., check.names = FALSE)`: arguments imply differing number of rows: 1, 34 [only occurs in testing, not in use] + # possibly an issue with locale, timezone etc? NetFrame <- cbind.data.frame( Sender, AnsweredTo, diff --git a/R/plot_replytimes.R b/R/plot_replytimes.R index b22aef2..8b32f5d 100644 --- a/R/plot_replytimes.R +++ b/R/plot_replytimes.R @@ -2,8 +2,8 @@ #' @description Visualizes the reply times and reaction times to messages per author #' @param data A WhatsApp chat log that was parsed with \code{\link[WhatsR]{parse_chat}}. #' @param names A vector of author names that the plots will be restricted to. -#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". -#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". +#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. +#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. #' @param return_data If TRUE, returns a data frame of response times extracted from the chat for more elaborate plotting. Default is FALSE. #' @param aggregate_sessions If TRUE, concurrent messages of the same author are aggregated into one session. Default is TRUE. #' @param plot Type of plot to be returned, options are "box" and "heatmap". @@ -30,7 +30,7 @@ plot_replytimes <- function(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(),tz = "UTC")), return_data = FALSE, aggregate_sessions = TRUE, plot = "box", @@ -41,10 +41,14 @@ plot_replytimes <- function(data, `.` <- Sender <- ReactionTime <- day <- hour <- median <- `Median Reply time` <- NULL # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # start- and endtime are convertable to POSIXct - if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.") + if (is.character(starttime) == FALSE | is.na(anytime(starttime, asUTC=TRUE,tz="UTC"))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (is.character(endtime) == FALSE | is.na(anytime(endtime, asUTC=TRUE,tz="UTC"))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (anytime(starttime, asUTC=TRUE,tz="UTC") >= anytime(endtime, asUTC=TRUE,tz="UTC")) stop("starttime has to be before endtime.") # return_data must be bool if (!is.logical(return_data)) stop("'return_data' has to be either TRUE or FALSE.") @@ -62,17 +66,17 @@ plot_replytimes <- function(data, if (!is.logical(exclude_sm)) stop("exclude_sm has to be either TRUE or FALSE.") # setting starttime - if (starttime == anytime("1960-01-01 00:00")) { - starttime <- min(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(starttime, asUTC=TRUE,tz="UTC") <= min(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + starttime <- min(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - starttime <- anytime(starttime, asUTC = TRUE) + starttime <- anytime(starttime, asUTC=TRUE,tz="UTC") } # setting endtime - if (difftime(Sys.time(), endtime, units = "min") < 1) { - endtime <- max(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(endtime, asUTC=TRUE,tz="UTC") >= max(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + endtime <- max(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - endtime <- anytime(endtime, asUTC = TRUE) + endtime <- anytime(endtime, asUTC=TRUE,tz="UTC") } # setting names argument diff --git a/R/plot_smilies.R b/R/plot_smilies.R index b8ed9ca..cc3eec8 100644 --- a/R/plot_smilies.R +++ b/R/plot_smilies.R @@ -2,8 +2,8 @@ #' @description Plots the smilies used in WhatsApp chat logs by sender #' @param data A WhatsApp chat log that was parsed with \code{\link[WhatsR]{parse_chat}}. #' @param names A vector of author names that the plots will be restricted to. -#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". -#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". +#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. +#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. #' @param min_occur The minimum number of occurrences a smiley has to have to be included in the visualization. Default is 1. #' @param return_data If TRUE, returns a data frame of smilies extracted from the chat for more elaborate plotting. Default is FALSE. #' @param smilie_vec A vector of smilies that the visualizations will be restricted to. @@ -22,7 +22,7 @@ plot_smilies <- function(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(),tz = "UTC")), min_occur = 1, return_data = FALSE, smilie_vec = "all", @@ -33,10 +33,14 @@ plot_smilies <- function(data, day <- hour <- n <- `Number of Smilies` <- ave <- total <- Var1 <- Freq <- n <- DateTime <- Total <- Sender <- Smilies <- Amount <- NULL # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # start- and endtime are convertable to POSIXct - if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.") + if (is.character(starttime) == FALSE | is.na(anytime(starttime, asUTC=TRUE,tz="UTC"))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (is.character(endtime) == FALSE | is.na(anytime(endtime, asUTC=TRUE,tz="UTC"))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (anytime(starttime, asUTC=TRUE,tz="UTC") >= anytime(endtime, asUTC=TRUE,tz="UTC")) stop("starttime has to be before endtime.") # min_occur must be >= 1 if (min_occur < 1) stop("Please provide a 'min_occur' of >= 1.") @@ -54,17 +58,17 @@ plot_smilies <- function(data, if (!is.logical(exclude_sm)) stop("'exclude_sm' has to be either TRUE or FALSE.") # setting starttime - if (starttime == anytime("1960-01-01 00:00")) { - starttime <- min(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(starttime, asUTC=TRUE,tz="UTC") <= min(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + starttime <- min(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - starttime <- anytime(starttime, asUTC = TRUE) + starttime <- anytime(starttime, asUTC=TRUE,tz="UTC") } # setting endtime - if (difftime(Sys.time(), endtime, units = "min") < 1) { - endtime <- max(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(endtime, asUTC=TRUE,tz="UTC") >= max(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + endtime <- max(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - endtime <- anytime(endtime, asUTC = TRUE) + endtime <- anytime(endtime, asUTC=TRUE,tz="UTC") } # setting names argument @@ -115,16 +119,16 @@ plot_smilies <- function(data, NewDates[[i]] <- rep(data$DateTime[i], NoElements[i]) } - NewDates <- as.POSIXct(unlist(NewDates), origin = "1970-01-01") + NewDates <- as.POSIXct(unlist(NewDates), origin = "1970-01-01",tz="UTC") # pasting together options(stringsAsFactors = FALSE) NewFrame <- cbind.data.frame(NewDates, NewSender, NewSmilies) # creating time data - NewFrame$hour <- as.POSIXlt(NewFrame$NewDates)$hour - NewFrame$year <- as.POSIXlt(NewFrame$NewDates)$year + 1900 - NewFrame$day <- weekdays(as.POSIXlt(NewFrame$NewDates), abbreviate = FALSE) + NewFrame$hour <- as.POSIXlt(NewFrame$NewDates,tz = "UTC")$hour + NewFrame$year <- as.POSIXlt(NewFrame$NewDates,tz = "UTC")$year + 1900 + NewFrame$day <- weekdays(as.POSIXlt(NewFrame$NewDates,tz = "UTC"), abbreviate = FALSE) # setting correct smilie_vec if (length(smilie_vec) == 1 && smilie_vec == "all") { diff --git a/R/plot_tokens.R b/R/plot_tokens.R index c12cab7..e9386d4 100644 --- a/R/plot_tokens.R +++ b/R/plot_tokens.R @@ -2,8 +2,8 @@ #' @description Visualizing token distribution per person #' @param data A WhatsApp chatlog that was parsed with \code{\link[WhatsR]{parse_chat}}. #' @param names A vector of author names that the plots will be restricted to. -#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". -#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". +#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. +#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. #' @param plot The type of plot to be used. Options include "bar","box","violin" and "cumsum". Default is "bar". #' @param return_data If TRUE, returns the subsetted data frame. Default is FALSE. #' @param exclude_sm If TRUE, excludes the WhatsApp System Messages from the descriptive statistics. Default is FALSE. @@ -23,7 +23,7 @@ plot_tokens <- function(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(),tz = "UTC")), plot = "bar", return_data = FALSE, exclude_sm = FALSE) { @@ -32,10 +32,14 @@ plot_tokens <- function(data, tokens <- freq <- word <- Sender <- TokCount <- DateTime <- total <- NULL # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # start- and endtime are convertable to POSIXct - if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.") + if (is.character(starttime) == FALSE | is.na(anytime(starttime, asUTC=TRUE,tz="UTC"))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (is.character(endtime) == FALSE | is.na(anytime(endtime, asUTC=TRUE,tz="UTC"))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (anytime(starttime, asUTC=TRUE,tz="UTC") >= anytime(endtime, asUTC=TRUE,tz="UTC")) stop("starttime has to be before endtime.") # return_data must be bool if (!is.logical(return_data)) stop("'return_data' has to be either TRUE or FALSE.") @@ -47,17 +51,17 @@ plot_tokens <- function(data, if (!is.logical(exclude_sm)) stop("exclude_sm has to be either TRUE or FALSE.")# # setting starttime - if (starttime == anytime("1960-01-01 00:00")) { - starttime <- min(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(starttime, asUTC=TRUE,tz="UTC") <= min(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + starttime <- min(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - starttime <- anytime(starttime, asUTC = TRUE) + starttime <- anytime(starttime, asUTC=TRUE,tz="UTC") } # setting endtime - if (difftime(Sys.time(), endtime, units = "min") < 1) { - endtime <- max(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(endtime, asUTC=TRUE,tz="UTC") >= max(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + endtime <- max(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - endtime <- anytime(endtime, asUTC = TRUE) + endtime <- anytime(endtime, asUTC=TRUE,tz="UTC") } # setting names argument diff --git a/R/plot_tokens_over_time.R b/R/plot_tokens_over_time.R index 974c54f..cce27ef 100644 --- a/R/plot_tokens_over_time.R +++ b/R/plot_tokens_over_time.R @@ -3,8 +3,8 @@ #' @param data A WhatsApp chat log that was parsed with \code{\link[WhatsR]{parse_chat}} with parameters anonimize = FALSE or anonimize = "add". #' @param names A vector of author names that the plots will be restricted to. #' @param names_col A column indicated by a string that should be accessed to determine the names. Only needs to be changed when \code{\link[WhatsR]{parse_chat}} used the parameter anon = "add" and the column "Anonymous" should be used. Default is "Sender". -#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". -#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". +#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. +#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. #' @param plot Type of plot to be returned. Options are "year", "day", "hour", "heatmap" and "alltime". Default is "alltime". #' @param return_data If TRUE, returns the subset data frame. Default is FALSE. #' @param exclude_sm If TRUE, excludes the WhatsApp system messages from the descriptive statistics. Default is FALSE. @@ -25,7 +25,7 @@ plot_tokens_over_time <- function(data, names = "all", names_col = "Sender", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(),tz = "UTC")), plot = "alltime", return_data = FALSE, exclude_sm = FALSE) { @@ -34,10 +34,14 @@ plot_tokens_over_time <- function(data, DateTime <- TokCount <- Sender <- year <- day <- hour <- `Number of Tokens` <- NULL # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # start- and endtime are convertable to POSIXct - if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.") + if (is.character(starttime) == FALSE | is.na(anytime(starttime, asUTC=TRUE,tz="UTC"))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (is.character(endtime) == FALSE | is.na(anytime(endtime, asUTC=TRUE,tz="UTC"))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (anytime(starttime, asUTC=TRUE,tz="UTC") >= anytime(endtime, asUTC=TRUE,tz="UTC")) stop("starttime has to be before endtime.") # return_data must be bool if (!is.logical(return_data)) stop("'return_data' has to be either TRUE or FALSE.") @@ -49,17 +53,17 @@ plot_tokens_over_time <- function(data, if (!is.logical(exclude_sm)) stop("exclude_sm has to be either TRUE or FALSE.") # setting starttime - if (starttime == anytime("1960-01-01 00:00")) { - starttime <- min(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(starttime, asUTC=TRUE,tz="UTC") <= min(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + starttime <- min(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - starttime <- anytime(starttime, asUTC = TRUE) + starttime <- anytime(starttime, asUTC=TRUE,tz="UTC") } # setting endtime - if (difftime(Sys.time(), endtime, units = "min") < 1) { - endtime <- max(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(endtime, asUTC=TRUE,tz="UTC") >= max(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + endtime <- max(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - endtime <- anytime(endtime, asUTC = TRUE) + endtime <- anytime(endtime, asUTC=TRUE,tz="UTC") } # setting names argument @@ -85,9 +89,9 @@ plot_tokens_over_time <- function(data, helperframe <- data[, c("DateTime", "Sender", "TokCount")] # creating time data - helperframe$hour <- as.POSIXlt(helperframe$DateTime)$hour - helperframe$year <- as.POSIXlt(helperframe$DateTime)$year + 1900 - helperframe$day <- weekdays(as.POSIXlt(helperframe$DateTime), abbreviate = FALSE) + helperframe$hour <- as.POSIXlt(helperframe$DateTime,tz="UTC")$hour + helperframe$year <- as.POSIXlt(helperframe$DateTime,tz="UTC")$year + 1900 + helperframe$day <- weekdays(as.POSIXlt(helperframe$DateTime,tz="UTC"), abbreviate = FALSE) # basic barchart if (plot == "alltime") { diff --git a/R/plot_wordcloud.R b/R/plot_wordcloud.R index b3c9fea..231ce5a 100644 --- a/R/plot_wordcloud.R +++ b/R/plot_wordcloud.R @@ -2,8 +2,8 @@ #' @description Creates a wordcloud by author for WhatsApp chat logs. Requires raw message text to be present in data. #' @param data A WhatsApp chat log that was parsed with \code{\link[WhatsR]{parse_chat}} and anonimize = FALSE or anonimize = "add" #' @param names A vector of author names that the plots will be restricted to. -#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". -#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". +#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. +#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. #' @param stop The language for stopword removal. Stopwords are taken from \code{\link[tm]{stopwords}}. Options are "english" and "german". #' @param comparison Must be TRUE or FALSE. If TRUE, will split up wordcloud by sender. Default is FALSE. #' @param return_data Will return the data frame used to create the plot if TRUE. Default is FALSE. @@ -26,7 +26,7 @@ plot_wordcloud <- function(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(),tz = "UTC")), remove_stops = TRUE, stop = "english", comparison = FALSE, @@ -39,10 +39,14 @@ plot_wordcloud <- function(data, `tokens` <- `freq` <- `word` <- NULL # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # start- and endtime are convertable to POSIXct - if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.") + if (is.character(starttime) == FALSE | is.na(anytime(starttime, asUTC=TRUE,tz="UTC"))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (is.character(endtime) == FALSE | is.na(anytime(endtime, asUTC=TRUE,tz="UTC"))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (anytime(starttime, asUTC=TRUE,tz="UTC") >= anytime(endtime, asUTC=TRUE,tz="UTC")) stop("starttime has to be before endtime.") # font_size must be >= 1 if (font_size < 1) stop("Please provide a 'font_size' of >= 1.") @@ -69,17 +73,17 @@ plot_wordcloud <- function(data, tm_stopwords <- readRDS(system.file("tm_stopwords.rds", package = "WhatsR")) # setting starttime - if (starttime == anytime("1960-01-01 00:00")) { - starttime <- min(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(starttime, asUTC=TRUE,tz="UTC") <= min(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + starttime <- min(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - starttime <- anytime(starttime, asUTC = TRUE) + starttime <- anytime(starttime, asUTC=TRUE,tz="UTC") } # setting endtime - if (difftime(Sys.time(), endtime, units = "min") < 1) { - endtime <- max(anytime(data$DateTime, asUTC = TRUE)) + if (anytime(endtime, asUTC=TRUE,tz="UTC") >= max(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + endtime <- max(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - endtime <- anytime(endtime, asUTC = TRUE) + endtime <- anytime(endtime, asUTC=TRUE,tz="UTC") } # setting names argument diff --git a/R/summarize_chat.R b/R/summarize_chat.R index bf566ac..dcb18cd 100644 --- a/R/summarize_chat.R +++ b/R/summarize_chat.R @@ -26,6 +26,10 @@ summarize_chat <- function(data, exclude_sm = FALSE) { # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # exclude_sm must be bool if (!is.logical(exclude_sm)) stop("exclude_sm has to be either TRUE or FALSE.") diff --git a/R/summarize_tokens_per_person.R b/R/summarize_tokens_per_person.R index 9d3725b..af59e3e 100644 --- a/R/summarize_tokens_per_person.R +++ b/R/summarize_tokens_per_person.R @@ -2,8 +2,8 @@ #' @description Summarizing the distribution of tokens for sent messages #' @param data A WhatsApp chat log that was parsed with \code{\link[WhatsR]{parse_chat}}. #' @param names A vector of author names that the plots will be restricted to. -#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". -#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". +#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. +#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. #' @param exclude_sm If TRUE, excludes the WhatsApp system messages from the descriptive statistics. Default is FALSE. #' @importFrom anytime anytime #' @export @@ -16,14 +16,18 @@ summarize_tokens_per_person <- function(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(),tz = "UTC")), exclude_sm = FALSE) { # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # start- and endtime are convertable to POSIXct - if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.") + if (is.character(starttime) == FALSE | is.na(anytime(starttime, asUTC=TRUE,tz="UTC"))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (is.character(endtime) == FALSE | is.na(anytime(endtime, asUTC=TRUE,tz="UTC"))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (anytime(starttime, asUTC=TRUE,tz="UTC") >= anytime(endtime, asUTC=TRUE,tz="UTC")) stop("starttime has to be before endtime.") # names in data or all names if (!("all" %in% names) & any(!names %in% data$Sender)) stop("names has to either be \"all\" or a vector of names to include.") @@ -32,17 +36,17 @@ summarize_tokens_per_person <- function(data, if (!is.logical(exclude_sm)) stop("excludeSM has to be either TRUE or FALSE.") # setting starttime - if (starttime == anytime("1960-01-01 00:00")) { - starttime <- min(anytime(data$DateTime)) + if (anytime(starttime, asUTC=TRUE,tz="UTC") <= min(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + starttime <- min(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - starttime <- anytime(starttime, asUTC = TRUE) + starttime <- anytime(starttime, asUTC=TRUE,tz="UTC") } # setting endtime - if (difftime(Sys.time(), endtime, units = "min") < 1) { - endtime <- max(data$DateTime) + if (anytime(endtime, asUTC=TRUE,tz="UTC") >= max(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + endtime <- max(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - endtime <- anytime(endtime, asUTC = TRUE) + endtime <- anytime(endtime, asUTC=TRUE,tz="UTC") } # setting names argument diff --git a/R/tailor_chat.R b/R/tailor_chat.R index 6e08ef4..7b2affb 100644 --- a/R/tailor_chat.R +++ b/R/tailor_chat.R @@ -2,8 +2,8 @@ #' @description Excluding parts of the chat by senders or timestamps #' @param data A WhatsApp chat log that was parsed with \code{\link[WhatsR]{parse_chat}}. #' @param names A vector of names that the output is restricted to. Messages from other non-contained authors are excluded. -#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". -#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". +#' @param starttime Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. +#' @param endtime Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps. #' @param exclude_sm If TRUE, excludes the WhatsApp system messages from the descriptive statistics. Default is FALSE. #' @importFrom anytime anytime #' @export @@ -16,14 +16,18 @@ tailor_chat <- function(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(),tz = "UTC")), exclude_sm = FALSE) { # catching bad params + + # checking data + if(!is.data.frame(data)){stop("'data' must be a dataframe parsed with parse_chat()")} + # start- and endtime are convertable to POSIXct - if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") - if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.") + if (is.character(starttime) == FALSE | is.na(anytime(starttime, asUTC=TRUE,tz="UTC"))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (is.character(endtime) == FALSE | is.na(anytime(endtime, asUTC=TRUE,tz="UTC"))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().") + if (anytime(starttime, asUTC=TRUE,tz="UTC") >= anytime(endtime, asUTC=TRUE,tz="UTC")) stop("starttime has to be before endtime.") # names in data or all names if (!("all" %in% names) & any(!names %in% data$Sender)) stop("names has to either be \"all\" or a vector of names to include.") @@ -32,17 +36,17 @@ tailor_chat <- function(data, if (!is.logical(exclude_sm)) stop("exclude_sm has to be either TRUE or FALSE.") # setting starttime - if (starttime == anytime("1960-01-01 00:00")) { - starttime <- min(anytime(data$DateTime)) + if (anytime(starttime, asUTC=TRUE,tz="UTC") <= min(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + starttime <- min(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - starttime <- anytime(starttime) + starttime <- anytime(starttime, asUTC=TRUE,tz="UTC") } # setting endtime - if (difftime(Sys.time(), endtime, units = "min") < 1) { - endtime <- max(anytime(data$DateTime)) + if (anytime(endtime, asUTC=TRUE,tz="UTC") >= max(anytime(data$DateTime, asUTC=TRUE,tz="UTC"))) { + endtime <- max(anytime(data$DateTime, asUTC=TRUE,tz="UTC")) } else { - endtime <- anytime(endtime) + endtime <- anytime(endtime, asUTC=TRUE,tz="UTC") } # setting names argument diff --git a/inst/TailoredData2.rds b/inst/TailoredData2.rds index dc5140c..abab0bd 100644 Binary files a/inst/TailoredData2.rds and b/inst/TailoredData2.rds differ diff --git a/inst/TailoredData3.rds b/inst/TailoredData3.rds index ed3fc96..0a625b7 100644 Binary files a/inst/TailoredData3.rds and b/inst/TailoredData3.rds differ diff --git a/inst/test_emoji2.rds b/inst/test_emoji2.rds index bbceb85..6a6565c 100644 Binary files a/inst/test_emoji2.rds and b/inst/test_emoji2.rds differ diff --git a/inst/test_emoji3.rds b/inst/test_emoji3.rds index ed686f4..8b2bbed 100644 Binary files a/inst/test_emoji3.rds and b/inst/test_emoji3.rds differ diff --git a/inst/test_links2.rds b/inst/test_links2.rds index c5c828b..5b121e0 100644 Binary files a/inst/test_links2.rds and b/inst/test_links2.rds differ diff --git a/inst/test_links3.rds b/inst/test_links3.rds index c100301..14e92c3 100644 Binary files a/inst/test_links3.rds and b/inst/test_links3.rds differ diff --git a/inst/test_media1.rds b/inst/test_media1.rds index fd0c772..c0f5aef 100644 Binary files a/inst/test_media1.rds and b/inst/test_media1.rds differ diff --git a/inst/test_media3.rds b/inst/test_media3.rds index 05839b3..8877a1c 100644 Binary files a/inst/test_media3.rds and b/inst/test_media3.rds differ diff --git a/inst/test_smilies3.rds b/inst/test_smilies3.rds index db42963..5ebb5b2 100644 Binary files a/inst/test_smilies3.rds and b/inst/test_smilies3.rds differ diff --git a/inst/test_smilies4.rds b/inst/test_smilies4.rds index e620b72..e017a2e 100644 Binary files a/inst/test_smilies4.rds and b/inst/test_smilies4.rds differ diff --git a/man/create_chatlog.Rd b/man/create_chatlog.Rd index 64f3140..e047c13 100644 --- a/man/create_chatlog.Rd +++ b/man/create_chatlog.Rd @@ -45,9 +45,9 @@ create_chatlog( \item{n_sdp}{Number of messages that contain self-deleting photos. Must be smaller or equal to n_messages.} -\item{startdate}{Earliest possible date for messages. Format is 'dd.mm.yyyy'. Timestamps for messages are created automatically between startdate and enddate.} +\item{startdate}{Earliest possible date for messages. Format is 'dd.mm.yyyy'. Timestamps for messages are created automatically between startdate and enddate. Input is interpreted as UTC} -\item{enddate}{Latest possible date for messages. Format is 'dd.mm.yyyy'. Timestamps for messages are created automatically between startdate and enddate.} +\item{enddate}{Latest possible date for messages. Format is 'dd.mm.yyyy'. Timestamps for messages are created automatically between startdate and enddate. Input is interpreted as UTC} \item{language}{Parameter for the language setting of the exporting phone. Influences structure of system messages} diff --git a/man/figures/2.png b/man/figures/2.png deleted file mode 100644 index 9ca9dbb..0000000 Binary files a/man/figures/2.png and /dev/null differ diff --git a/man/plot_emoji.Rd b/man/plot_emoji.Rd index bedae8f..38c2ad2 100644 --- a/man/plot_emoji.Rd +++ b/man/plot_emoji.Rd @@ -8,7 +8,7 @@ plot_emoji( data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), min_occur = 1, return_data = FALSE, emoji_vec = "all", @@ -23,9 +23,9 @@ plot_emoji( \item{names}{A vector of author names that the plots will be restricted to.} -\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} -\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} \item{min_occur}{Minimum number of occurrences for emoji to be included in the plots. Default is 1.} diff --git a/man/plot_lexical_dispersion.Rd b/man/plot_lexical_dispersion.Rd index d2a8ff0..e0fb920 100644 --- a/man/plot_lexical_dispersion.Rd +++ b/man/plot_lexical_dispersion.Rd @@ -8,7 +8,7 @@ plot_lexical_dispersion( data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), keywords = c("hello", "world"), return_data = FALSE, exclude_sm = FALSE, @@ -20,9 +20,9 @@ plot_lexical_dispersion( \item{names}{A vector of author names that the plots will be restricted to.} -\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} -\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} \item{keywords}{A vector of keywords to be displayed, default is c("hello","world").} diff --git a/man/plot_links.Rd b/man/plot_links.Rd index 6920a84..4dd95ab 100644 --- a/man/plot_links.Rd +++ b/man/plot_links.Rd @@ -8,7 +8,7 @@ plot_links( data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), use_domains = TRUE, exclude_long = 50, min_occur = 1, @@ -23,9 +23,9 @@ plot_links( \item{names}{A vector of author names that the plots will be restricted to.} -\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} -\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} \item{use_domains}{If TRUE, links are shortened to domains. This includes the inputs in link_vec. Default is TRUE.} diff --git a/man/plot_locations.Rd b/man/plot_locations.Rd index 15b9c71..b2aef19 100644 --- a/man/plot_locations.Rd +++ b/man/plot_locations.Rd @@ -8,7 +8,7 @@ plot_locations( data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), mapzoom = 5, return_data = FALSE, jitter_value = 0.01, @@ -22,9 +22,9 @@ plot_locations( \item{names}{A vector of author names that the plots will be restricted to.} -\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} -\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} \item{mapzoom}{Value for zoom into the map passed down to \code{\link[ggmap]{get_map}}. Default value is 5. Higher zoom will auto-download more map files which can take a while.} diff --git a/man/plot_media.Rd b/man/plot_media.Rd index 6f56d27..45ed271 100644 --- a/man/plot_media.Rd +++ b/man/plot_media.Rd @@ -8,7 +8,7 @@ plot_media( data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), use_filetype = TRUE, min_occur = 1, return_data = FALSE, @@ -22,9 +22,9 @@ plot_media( \item{names}{A vector of author names that the plots will be restricted to.} -\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} -\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} \item{use_filetype}{If TRUE, shortens sent file attachments to file types.} diff --git a/man/plot_messages.Rd b/man/plot_messages.Rd index 1e1ab42..e9e6bbc 100644 --- a/man/plot_messages.Rd +++ b/man/plot_messages.Rd @@ -8,7 +8,7 @@ plot_messages( data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "bar", return_data = FALSE, exclude_sm = FALSE @@ -19,9 +19,9 @@ plot_messages( \item{names}{A vector of author names that the plots will be restricted to.} -\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} -\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} \item{plot}{Type of plot to be returned, options are "bar", "cumsum", "heatmap" and "pie". Default is "bar".} diff --git a/man/plot_network.Rd b/man/plot_network.Rd index a63b35b..2071485 100644 --- a/man/plot_network.Rd +++ b/man/plot_network.Rd @@ -8,7 +8,7 @@ plot_network( data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), return_data = FALSE, collapse_sessions = FALSE, edgetype = "n", @@ -20,9 +20,9 @@ plot_network( \item{names}{A vector of author names that the visualization will be restricted to. Non-listed authors will be removed.} -\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Input is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} -\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Input is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} \item{return_data}{If TRUE, returns a data frame of subsequent interactions with senders and recipients. Default is FALSE.} diff --git a/man/plot_replytimes.Rd b/man/plot_replytimes.Rd index 480acf7..9950bb6 100644 --- a/man/plot_replytimes.Rd +++ b/man/plot_replytimes.Rd @@ -8,7 +8,7 @@ plot_replytimes( data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), return_data = FALSE, aggregate_sessions = TRUE, plot = "box", @@ -21,9 +21,9 @@ plot_replytimes( \item{names}{A vector of author names that the plots will be restricted to.} -\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} -\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} \item{return_data}{If TRUE, returns a data frame of response times extracted from the chat for more elaborate plotting. Default is FALSE.} diff --git a/man/plot_smilies.Rd b/man/plot_smilies.Rd index 22ea9fe..502b906 100644 --- a/man/plot_smilies.Rd +++ b/man/plot_smilies.Rd @@ -8,7 +8,7 @@ plot_smilies( data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), min_occur = 1, return_data = FALSE, smilie_vec = "all", @@ -21,9 +21,9 @@ plot_smilies( \item{names}{A vector of author names that the plots will be restricted to.} -\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} -\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} \item{min_occur}{The minimum number of occurrences a smiley has to have to be included in the visualization. Default is 1.} diff --git a/man/plot_tokens.Rd b/man/plot_tokens.Rd index 301bf8e..a0f3755 100644 --- a/man/plot_tokens.Rd +++ b/man/plot_tokens.Rd @@ -8,7 +8,7 @@ plot_tokens( data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "bar", return_data = FALSE, exclude_sm = FALSE @@ -19,9 +19,9 @@ plot_tokens( \item{names}{A vector of author names that the plots will be restricted to.} -\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} -\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} \item{plot}{The type of plot to be used. Options include "bar","box","violin" and "cumsum". Default is "bar".} diff --git a/man/plot_tokens_over_time.Rd b/man/plot_tokens_over_time.Rd index dec3db0..a5dba13 100644 --- a/man/plot_tokens_over_time.Rd +++ b/man/plot_tokens_over_time.Rd @@ -9,7 +9,7 @@ plot_tokens_over_time( names = "all", names_col = "Sender", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "alltime", return_data = FALSE, exclude_sm = FALSE @@ -22,9 +22,9 @@ plot_tokens_over_time( \item{names_col}{A column indicated by a string that should be accessed to determine the names. Only needs to be changed when \code{\link[WhatsR]{parse_chat}} used the parameter anon = "add" and the column "Anonymous" should be used. Default is "Sender".} -\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} -\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} \item{plot}{Type of plot to be returned. Options are "year", "day", "hour", "heatmap" and "alltime". Default is "alltime".} diff --git a/man/plot_wordcloud.Rd b/man/plot_wordcloud.Rd index e25ac16..71ad3ca 100644 --- a/man/plot_wordcloud.Rd +++ b/man/plot_wordcloud.Rd @@ -8,7 +8,7 @@ plot_wordcloud( data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), remove_stops = TRUE, stop = "english", comparison = FALSE, @@ -23,9 +23,9 @@ plot_wordcloud( \item{names}{A vector of author names that the plots will be restricted to.} -\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} -\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} \item{remove_stops}{Either TRUE or FALSE, default is TRUE. Configures whether stopwords from \code{\link[tm]{stopwords}} are removed from the text strings.} diff --git a/man/summarize_tokens_per_person.Rd b/man/summarize_tokens_per_person.Rd index ce69aad..30b7876 100644 --- a/man/summarize_tokens_per_person.Rd +++ b/man/summarize_tokens_per_person.Rd @@ -8,7 +8,7 @@ summarize_tokens_per_person( data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), exclude_sm = FALSE ) } @@ -17,9 +17,9 @@ summarize_tokens_per_person( \item{names}{A vector of author names that the plots will be restricted to.} -\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} -\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} \item{exclude_sm}{If TRUE, excludes the WhatsApp system messages from the descriptive statistics. Default is FALSE.} } diff --git a/man/tailor_chat.Rd b/man/tailor_chat.Rd index f65a812..db32529 100644 --- a/man/tailor_chat.Rd +++ b/man/tailor_chat.Rd @@ -8,7 +8,7 @@ tailor_chat( data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), exclude_sm = FALSE ) } @@ -17,9 +17,9 @@ tailor_chat( \item{names}{A vector of names that the output is restricted to. Messages from other non-contained authors are excluded.} -\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{starttime}{Datetime that is used as the minimum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} -\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm".} +\item{endtime}{Datetime that is used as the maximum boundary for exclusion. Is parsed with \code{\link[anytime]{anytime}}. Standard format is "yyyy-mm-dd hh:mm". Is interpreted as UTC to be compatible with WhatsApp timestamps.} \item{exclude_sm}{If TRUE, excludes the WhatsApp system messages from the descriptive statistics. Default is FALSE.} } diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf new file mode 100644 index 0000000..e5eed98 Binary files /dev/null and b/tests/testthat/Rplots.pdf differ diff --git a/tests/testthat/test-WhatsR-tests.R b/tests/testthat/test-WhatsR-tests.R index 74d30e4..9470ae0 100644 --- a/tests/testthat/test-WhatsR-tests.R +++ b/tests/testthat/test-WhatsR-tests.R @@ -1,5 +1,6 @@ #################### TESTING ESSENTIAL FUNCTIONS ##################### + #### Testing updating of emoji dictionary test_that("Updating emoji dictionary",{ @@ -908,20 +909,20 @@ test_that("tailoring function", { tailored_data3 <- tailor_chat(data, names = "Dave", starttime = "2018-01-29 12:24:03", - endtime = "2018-01-30 00:13:03", + endtime = "2018-01-29 23:33:03", exclude_sm = TRUE ) # generate and write file [Use this to recreate test files when parse_chat() changed] #saveRDS(tailored_data3,"TailoredData3.rds",version = 2) - tailored_data <- readRDS(system.file("TailoredData3.rds", package = "WhatsR")) + test <- readRDS(system.file("TailoredData3.rds", package = "WhatsR")) expect_identical(test, tailored_data3) tailored_data4 <- tailor_chat(data, names = "all", starttime = "2018-01-29 12:24:03", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), exclude_sm = TRUE ) @@ -969,7 +970,6 @@ suppressWarnings(test_that("Plotting Emoji", { test <- readRDS(system.file("test_emoji1.rds", package = "WhatsR")) suppressWarnings(expect_identical(test_emoji1, test)) - test_emoji2 <- hush(plot_emoji(data, names = "all", # starttime=, @@ -989,7 +989,6 @@ suppressWarnings(test_that("Plotting Emoji", { test <- readRDS(system.file("test_emoji2.rds", package = "WhatsR")) expect_identical(test_emoji2, test) - test_emoji3 <- hush(plot_emoji(data, names = "all", # starttime=, @@ -1044,7 +1043,7 @@ test_that("Plotting Links", { test_links1 <- plot_links(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), use_domains = TRUE, exclude_long = 50, min_occur = 1, @@ -1061,11 +1060,10 @@ test_that("Plotting Links", { expect_identical(test_links1, test) - test_links2 <- plot_links(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), use_domains = TRUE, exclude_long = 50, min_occur = 1, @@ -1081,13 +1079,10 @@ test_that("Plotting Links", { test <- readRDS(system.file("test_links2.rds", package = "WhatsR")) expect_identical(test_links2, test) - - - test_links3 <- plot_links(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), use_domains = FALSE, exclude_long = 50, min_occur = 1, @@ -1108,7 +1103,7 @@ test_that("Plotting Links", { test_links4 <- plot_links(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), use_domains = TRUE, exclude_long = 50, min_occur = 1, @@ -1137,11 +1132,10 @@ test_that("Plotting Media", { data <- hush(parse_chat(system.file("englishiosampm.txt", package = "WhatsR"))) - test_media1 <- plot_media(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), use_filetype = TRUE, min_occur = 1, return_data = TRUE, @@ -1159,7 +1153,7 @@ test_that("Plotting Media", { test_media2 <- plot_media(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), use_filetype = FALSE, min_occur = 1, return_data = TRUE, @@ -1174,14 +1168,10 @@ test_that("Plotting Media", { test <- readRDS(system.file("test_media2.rds", package = "WhatsR")) expect_identical(test_media2, test) - - # TODO: `geom_line()`: Each group consists of only one observation. - # ℹ Do you need to adjust the group aesthetic? - # invalid font type for hjust bullshit test_media3 <- plot_media(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), use_filetype = TRUE, min_occur = 1, return_data = TRUE, @@ -1199,7 +1189,7 @@ test_that("Plotting Media", { test_media4 <- plot_media(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), use_filetype = TRUE, min_occur = 1, return_data = TRUE, @@ -1307,7 +1297,7 @@ test_that("Plotting Messages", { test_messages1 <- plot_messages(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "bar", return_data = TRUE, exclude_sm = TRUE @@ -1319,14 +1309,10 @@ test_that("Plotting Messages", { test <- readRDS(system.file("test_messages1.rds", package = "WhatsR")) expect_identical(test_messages1, test) - - - - test_messages2 <- plot_messages(data, names = c("Carol", "Dave"), starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "bar", return_data = TRUE, exclude_sm = TRUE @@ -1338,12 +1324,10 @@ test_that("Plotting Messages", { test <- readRDS(system.file("test_messages2.rds", package = "WhatsR")) expect_identical(test_messages2, test) - - test_messages3 <- plot_messages(data, names = "all", starttime = "2018-01-30 00:11:20", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "pie", return_data = TRUE, exclude_sm = TRUE @@ -1355,13 +1339,10 @@ test_that("Plotting Messages", { test <- readRDS(system.file("test_messages3.rds", package = "WhatsR")) expect_identical(test_messages3, test) - - - test_messages4 <- plot_messages(data, names = c("Alice", "Bob"), starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "pie", return_data = TRUE, exclude_sm = TRUE @@ -1389,7 +1370,7 @@ test_that("Plotting Replytimes", { test_replytimes1 <- suppressMessages(plot_replytimes(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), return_data = TRUE, aggregate_sessions = TRUE, plot = "box", @@ -1407,7 +1388,7 @@ test_that("Plotting Replytimes", { test_replytimes2 <- suppressMessages(plot_replytimes(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), return_data = TRUE, aggregate_sessions = TRUE, plot = "box", @@ -1425,7 +1406,7 @@ test_that("Plotting Replytimes", { test_replytimes3 <- plot_replytimes(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), return_data = TRUE, aggregate_sessions = TRUE, plot = "heatmap", @@ -1443,7 +1424,7 @@ test_that("Plotting Replytimes", { test_replytimes4 <- plot_replytimes(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), return_data = TRUE, aggregate_sessions = TRUE, plot = "heatmap", @@ -1474,7 +1455,7 @@ test_that("Plotting tokens", { test_tokens1 <- suppressMessages(plot_tokens(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "bar", exclude_sm = TRUE, return_data = TRUE @@ -1489,7 +1470,7 @@ test_that("Plotting tokens", { test_tokens2 <- suppressMessages(plot_tokens(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "cumsum", exclude_sm = TRUE, return_data = TRUE @@ -1505,7 +1486,7 @@ test_that("Plotting tokens", { test_tokens3 <- suppressMessages(plot_tokens(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "violin", exclude_sm = TRUE, return_data = TRUE @@ -1521,7 +1502,7 @@ test_that("Plotting tokens", { test_tokens4 <- suppressMessages(plot_tokens(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "box", exclude_sm = TRUE, return_data = TRUE @@ -1549,7 +1530,7 @@ test_that("Plotting tokens over time", { test_tot1 <- suppressMessages(plot_tokens_over_time(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "alltime", return_data = TRUE, exclude_sm = TRUE @@ -1565,7 +1546,7 @@ test_that("Plotting tokens over time", { test_tot2 <- suppressMessages(plot_tokens_over_time(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "year", return_data = TRUE, exclude_sm = TRUE @@ -1581,7 +1562,7 @@ test_that("Plotting tokens over time", { test_tot3 <- suppressMessages(plot_tokens_over_time(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "day", return_data = TRUE, exclude_sm = TRUE @@ -1597,7 +1578,7 @@ test_that("Plotting tokens over time", { test_tot4 <- suppressMessages(plot_tokens_over_time(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), plot = "heatmap", return_data = TRUE, exclude_sm = TRUE @@ -1621,11 +1602,10 @@ test_that("Plotting Smilies", { data <- hush(parse_chat(system.file("englishiosampm.txt", package = "WhatsR"))) - test_smilies1 <- plot_smilies(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), min_occur = 1, return_data = TRUE, smilie_vec = "all", @@ -1643,7 +1623,7 @@ test_that("Plotting Smilies", { test_smilies2 <- plot_smilies(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), min_occur = 1, return_data = TRUE, smilie_vec = "all", @@ -1657,11 +1637,12 @@ test_that("Plotting Smilies", { test <- readRDS(system.file("test_smilies2.rds", package = "WhatsR")) expect_identical(test_smilies2, test) - #TODO: ERROR: invalid font type [only occurs in testing, not in use] + # TODO: This fails only when running check from RStudio, not with devtools::test() + # Seems to be a bug: https://github.com/hadley/r-pkgs/issues/483 # test_smilies3 <- plot_smilies(data, # names = "all", - # starttime = anytime("1960-01-01 00:00",asUTC = TRUE), - # endtime = Sys.time(), + # starttime = "1960-01-01 00:00", + # endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), # min_occur = 1, # return_data = TRUE, # smilie_vec = "all", @@ -1671,13 +1652,13 @@ test_that("Plotting Smilies", { # generate and write file [Use this to recreate test files when parse_chat() changed] #saveRDS(test_smilies3,"test_smilies3.rds",version = 2) - #test <- readRDS(system.file("test_smilies3.rds", package = "WhatsR")) - #expect_identical(test_smilies3,test) + # test <- readRDS(system.file("test_smilies3.rds", package = "WhatsR")) + # expect_identical(test_smilies3,test) test_smilies4 <- plot_smilies(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), min_occur = 1, return_data = TRUE, smilie_vec = "all", @@ -1707,7 +1688,7 @@ test_that("Plotting Wordcloud", { test_wc1 <- plot_wordcloud(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), remove_stops = TRUE, stop = "english", comparison = FALSE, @@ -1728,7 +1709,7 @@ test_that("Plotting Wordcloud", { test_wc2 <- plot_wordcloud(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), remove_stops = FALSE, stop = "english", comparison = TRUE, @@ -1747,7 +1728,7 @@ test_that("Plotting Wordcloud", { test_wc3 <- plot_wordcloud(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), remove_stops = TRUE, stop = "english", comparison = FALSE, @@ -1767,7 +1748,7 @@ test_that("Plotting Wordcloud", { test_wc4 <- plot_wordcloud(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), remove_stops = FALSE, stop = "english", comparison = TRUE, @@ -1798,7 +1779,7 @@ test_that("Plotting Network", { test_network1 <- plot_network(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), return_data = TRUE, collapse_sessions = FALSE, edgetype = "n", @@ -1811,12 +1792,12 @@ test_that("Plotting Network", { test <- readRDS(system.file("test_network1.rds", package = "WhatsR")) expect_identical(test_network1, test) - - # TODO: Error in `data.frame(..., check.names = FALSE)`: arguments imply differing number of rows: 1, 34 [only occurs in testing, not in use] + # TODO: This fails only when running check from RStudio, not with devtools::test() + # Seems to be a bug: https://github.com/hadley/r-pkgs/issues/483 # test_network2 <- plot_network(data, # names = "all", - # starttime = anytime("1960-01-01 00:00",asUTC = TRUE), - # endtime = Sys.time(), + # starttime = "1960-01-01 00:00", + # endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), # return_data = TRUE, # collapse_sessions = TRUE, # edgetype = "TokCount", @@ -1826,8 +1807,8 @@ test_that("Plotting Network", { # generate and write file [Use this to recreate test files when parse_chat() changed] #saveRDS(test_network2,"test_network2.rds",version = 2) - #test <- readRDS(system.file("test_network2.rds", package = "WhatsR")) - #expect_identical(test_network2, test) + # test <- readRDS(system.file("test_network2.rds", package = "WhatsR")) + # expect_identical(test_network2, test) test_network3 <- plot_network(data, names = "all", @@ -1845,20 +1826,21 @@ test_that("Plotting Network", { test <- readRDS(system.file("test_network3.rds", package = "WhatsR")) expect_identical(test_network3, test) - # TODO: Error in `data.frame(..., check.names = FALSE)`: arguments imply differing number of rows: 1, 34 [only occurs in testing, not in use] + # TODO: This fails only when running check from RStudio, not with devtools::test() + # Seems to be a bug: https://github.com/hadley/r-pkgs/issues/483 # test_network4 <- plot_network(data, # names = "all", - # starttime = anytime("1960-01-01 00:00",asUTC = TRUE), - # endtime = Sys.time(), + # starttime = "1960-01-01 00:00", + # endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), # return_data = TRUE, # collapse_sessions = TRUE, # edgetype = "SmilieCount", # exclude_sm = TRUE # ) - # + # # generate and write file [Use this to recreate test files when parse_chat() changed] # #saveRDS(test_network4,"test_network4.rds",version = 2) - # + # test <- readRDS(system.file("test_network4.rds", package = "WhatsR")) # expect_identical(test_network4, test) }) @@ -1877,7 +1859,7 @@ test_that("Plotting Lexical Dispersion", { test_lediplo1 <- plot_lexical_dispersion(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), return_data = TRUE, keywords = c("data", "consent"), exclude_sm = TRUE @@ -1892,7 +1874,7 @@ test_that("Plotting Lexical Dispersion", { test_lediplo2 <- plot_lexical_dispersion(data, names = c("Alice", "Bob"), starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), return_data = TRUE, keywords = c("data", "consent"), exclude_sm = TRUE @@ -1908,7 +1890,7 @@ test_that("Plotting Lexical Dispersion", { test_lediplo3 <- plot_lexical_dispersion(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), return_data = TRUE, keywords = c("data", "consent", "this"), exclude_sm = TRUE @@ -1924,7 +1906,7 @@ test_that("Plotting Lexical Dispersion", { test_lediplo4 <- plot_lexical_dispersion(data, names = "all", starttime = "1960-01-01 00:00", - endtime = as.character(Sys.time()), + endtime = as.character(as.POSIXct(Sys.time(), tz = "UTC")), return_data = TRUE, keywords = c("data", "consent"), exclude_sm = TRUE