R/zzz.R

Defines functions .onLoad get_today

#' Today's Date at Package Load Time
#'
#' This variable stores the current date (in "yyyymmdd" format) at the time the
#' package is loaded. It is useful for reproducible filenames (e.g., in
#' `saveViz()`), and is automatically set when the package is attached.
#'
#' @format A character string (e.g., "20250908").
#' @export
#'
#' @examples
#' # Print the date stored at package load
#' library(rChEA3)
#' today
#'
#' # Use it in a filename
#' paste0(today, "_rCHEA3_plot_meanRank.pdf")
today <- NULL

get_today <- function() {
    gsub("-", "", as.character(lubridate::today()))
}

.onLoad <- function(libname, pkgname) {
    # Assign to the namespace (for internal access)
    ns <- asNamespace(pkgname)
    assign("today", get_today(), envir = ns)

    # Assign to the package environment (for user access)
    assign("today", get_today(), envir = parent.env(environment()))
}

Try the rChEA3 package in your browser

Any scripts or data that you put into this service are public.

rChEA3 documentation built on Nov. 5, 2025, 6:49 p.m.