R/update_archived_data.R

Defines functions update_archived_data

Documented in update_archived_data

#' Update archived data
#' @description Read in current archived data, and update it.
#'
#' @param curr_data Archived data set from RapidPro (can be generated by `get_archived_data`).
#' @param period Default `"none"`. A character string giving the period of time. One of `"monthly"`, `"daily"`, or `"none"`.
#' @param date_to character string giving the date to filter the data to.
#' @param format_date from `as.POSIX*` function: character string giving a date-time format as used by `strptime`.
#' @param tzone_date from `as.POSIX*` function: time zone specification to be used for the conversion, if one is required. System-specific (see time zones), but "" is the current time zone, and "GMT" is UTC (Universal Time, Coordinated). Invalid values are most commonly treated as UTC, on some platforms with a warning.
#'
#' @return Updated archived data
#' @export
#'
# Example:
# archived_data_1 <- get_archived_data(period = "none", date_from = "2021-11-01", date_to = "2021-11-05")
# update_archived_data(curr_data = archived_data_1)
update_archived_data <- function(curr_data, period = "none", date_to = NULL, format_date = "%Y-%m-%d", tzone_date = "UTC"){
  date_from_update <- max(as.Date(names(curr_data))) + 1
  archived_data_new <- get_archived_data(period = period,
                                       date_from = date_from_update,
                                       date_to = date_to,
                                       format_date = format_date,
                                       tzone_date = tzone_date)
  archived_data <- c(curr_data, archived_data_new)
  return(archived_data)
}
lilyclements/Rapidreadr documentation built on April 17, 2025, 6:10 p.m.