R/utils.R

Defines functions fetch_metadata set_metadata

Documented in fetch_metadata set_metadata

# utils.R

# Create an environment to store the metadata
pkg_env <- new.env()

#' Set metadata
#' 
#' @description 
#' Sets the metadata for the package, which can be used across various functions.
#' 
#' @param meta A list containing metadata information.
#' 
#' @export
#' 
#' @examples
#' \dontrun{
#'  metadata <- gophr::get_metadata(file_path)
#'  set_metadata(metadata)
#' }
set_metadata <- function(meta) {
  if (!is.list(meta)) {
    stop("Metadata should be a list.")
  }
  # Store metadata in pgk env
  pkg_env$meta <-  suppressMessages(suppressWarnings(meta))
  invisible(NULL)
}

#' Fetch metadata
#' 
#' @description 
#' Retrieves the metadata set for the package.
#' 
#' @return A list containing metadata information.
#' 
#' @export
#' 
#' @examples
#' \dontrun{
#'  meta <- get_metadata()
#' }
fetch_metadata <- function() {
  if (!exists("meta", envir = pkg_env)) {
    stop("Metadata has not been set. Please use set_metadata() to set it.")
  }
  return(pkg_env$meta)
}
              
USAID-OHA-SI/selfdestructin5 documentation built on Feb. 23, 2025, 5:08 a.m.