Skip to content

Commit

Permalink
fix [skipci]
Browse files Browse the repository at this point in the history
  • Loading branch information
c1au6i0 committed Dec 19, 2024
1 parent 927ce35 commit e20241c
Showing 1 changed file with 0 additions and 65 deletions.
65 changes: 0 additions & 65 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e20241c

Please sign in to comment.