From e20241c8873e7e31e4b6efbedbed40383097c6d9 Mon Sep 17 00:00:00 2001 From: c1au6i0 Date: Wed, 18 Dec 2024 20:38:12 -0500 Subject: [PATCH] fix [skipci] --- R/utils.R | 65 ------------------------------------------------------- 1 file changed, 65 deletions(-) diff --git a/R/utils.R b/R/utils.R index 85eb4ed..81eafcd 100644 --- a/R/utils.R +++ b/R/utils.R @@ -93,71 +93,6 @@ check_internet <- function(verbose = TRUE) { } - - - - - -#' Save an object to the package cache -#' -#' This function saves an R object to the cache directory of the `extractox` package -#' using the `.rds` file format. If a file with the same name already exists in the cache, -#' it will be overwritten. -#' -#' @param obj Any R object to be saved. -#' @param file_name A character string specifying the name of the file (without extension). -#' @param verbose A logical value indicating whether to print detailed messages. Default is FALSE. -#' @return Invisibly returns the full path of the saved file. -#' @details The cache directory is determined using [tools::R_user_dir()] with the `cache` subdirectory -#' for the `extractox` package. If the directory does not exist, it is created automatically. -#' The function will overwrite any existing file with the same name. -#' @noRd -save_to_cache <- function(obj, file_name, verbose = FALSE) { - cache_dir <- tools::R_user_dir("extractox", which = "cache") - - if (!dir.exists(cache_dir)) { - dir.create(cache_dir, recursive = TRUE) - } - - file_path <- file.path(cache_dir, paste0(file_name, ".rds")) - - if (all(file.exists(file_path), verbose)){ - cli::cli_alert_info("Overwriting cache.") - } - - saveRDS(obj, file_path) - - invisible(file_path) -} - -#' Read an object from the package cache -#' -#' This function reads an R object from the cache directory of the `extractox` package -#' using the `.rds` file format. If the file does not exist, it stops. -#' -#' @param file_name A character string specifying the name of the file (without extension). -#' @param verbose A logical value indicating whether to print detailed messages. Default is FALSE. -#' @return The R object read from the cache, or NULL if the file does not exist. -#' @details The cache directory is determined using [tools::R_user_dir()] with the `cache` subdirectory -#' for the `extractox` package. If the file does not exist, a message is printed if verbose is TRUE. -#' @noRd -read_from_cache <- function(file_name, verbose = FALSE) { - cache_dir <- tools::R_user_dir("extractox", which = "cache") - file_path <- file.path(cache_dir, paste0(file_name, ".rds")) - - if (file.exists(file_path)) { - out <- readRDS(file_path) - if (verbose) { - cli::cli_alert_success("Successfully read from cache.") - } - } else { - cli::cli_abort("File not found in cache.") - } - - out -} - - #' Selection of assays of iris #' @keywords internal