R/append_log.R

Defines functions append_log

Documented in append_log

#' @title append_log
#' @description Creates a log in the form of a named list of character vectors, where each element of the vector is a log entry and the names of the list correspond to the entry date.
#' @param log_entry character, a log entry.
#' @return A named list of strings.
#' @examples 
#' \dontrun{
#' if(interactive()){
#'  append_log('Some log entry')
#'  }
#' }
#' @export 
append_log <- function(log_entry) {
  if (!dir.exists('log')) dir.create('log')
  if (file.exists('log/deploy_log.rds'))
    log <- readRDS('log/deploy_log.rds')
  else 
    log <- list()

  if (as.character(Sys.Date()) %in% names(log)) {
    log[as.character(Sys.Date())] <- log %>%
      .[[as.character(Sys.Date())]] %>%
      c(., log_entry) %>%
      list %>%
      `names<-`(Sys.Date())
  } else {
    log[as.character(Sys.Date())] <- log_entry
  }

  saveRDS(log, 'log/deploy_log.rds')
}
causality-loop/clhelpers documentation built on Aug. 31, 2022, 3:39 a.m.