Skip to content

Commit

Permalink
new function get_cache_dir()
Browse files Browse the repository at this point in the history
  • Loading branch information
dhersz committed Dec 9, 2024
1 parent b66aec8 commit b926619
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export(download_cnefe)
export(geocode)
export(geocodebr_cache)
export(get_cache_dir)
export(set_cache_dir)
importFrom(data.table,"%chin%")
importFrom(data.table,"%like%")
Expand Down
25 changes: 24 additions & 1 deletion R/set_cache_dir.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#'
#' @param path A string. The path to the directory used to cache the data. If
#' `NULL` (the default), the package will use a versioned directory saved
#' inside the directory returned by [tools::R_user_dir].
#' inside the directory returned by [tools::R_user_dir()].
#'
#' @return Invisibly returns the cache directory path.
#'
Expand Down Expand Up @@ -39,3 +39,26 @@ set_cache_dir <- function(path = NULL) {

return(invisible(cache_dir))
}

#' Get the cache directory used in geocodebr
#'
#' Gets the directory used to cache CNEFE data. Useful to inspect the directory
#' set with [set_cache_dir()] in a previous R session. Returns the default cache
#' directory if no custom directory has been previously set.
#'
#' @return The cache directory path.
#'
#' @examples
#' get_cache_dir()
#'
#' @export
get_cache_dir <- function() {
if (fs::file_exists(cache_config_file)) {
cache_dir <- readLines(cache_config_file)
cache_dir <- fs::path_norm(cache_dir)
} else {
cache_dir <- default_cache_dir
}

return(cache_dir)
}
20 changes: 20 additions & 0 deletions man/get_cache_dir.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/set_cache_dir.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b926619

Please sign in to comment.