From b92661946e08be7023de32501e62ccf77ed149d0 Mon Sep 17 00:00:00 2001 From: Daniel Herszenhut Date: Mon, 9 Dec 2024 17:03:52 -0300 Subject: [PATCH] new function get_cache_dir() --- NAMESPACE | 1 + R/set_cache_dir.R | 25 ++++++++++++++++++++++++- man/get_cache_dir.Rd | 20 ++++++++++++++++++++ man/set_cache_dir.Rd | 2 +- 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 man/get_cache_dir.Rd diff --git a/NAMESPACE b/NAMESPACE index 20748be..886eab5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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%") diff --git a/R/set_cache_dir.R b/R/set_cache_dir.R index 6080b79..d1b77df 100644 --- a/R/set_cache_dir.R +++ b/R/set_cache_dir.R @@ -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. #' @@ -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) +} diff --git a/man/get_cache_dir.Rd b/man/get_cache_dir.Rd new file mode 100644 index 0000000..fb86291 --- /dev/null +++ b/man/get_cache_dir.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/set_cache_dir.R +\name{get_cache_dir} +\alias{get_cache_dir} +\title{Get the cache directory used in geocodebr} +\usage{ +get_cache_dir() +} +\value{ +The cache directory path. +} +\description{ +Gets the directory used to cache CNEFE data. Useful to inspect the directory +set with \code{\link[=set_cache_dir]{set_cache_dir()}} in a previous R session. Returns the default cache +directory if no custom directory has been previously set. +} +\examples{ +get_cache_dir() + +} diff --git a/man/set_cache_dir.Rd b/man/set_cache_dir.Rd index 8b1f14f..a968e62 100644 --- a/man/set_cache_dir.Rd +++ b/man/set_cache_dir.Rd @@ -9,7 +9,7 @@ set_cache_dir(path = NULL) \arguments{ \item{path}{A string. The path to the directory used to cache the data. If \code{NULL} (the default), the package will use a versioned directory saved -inside the directory returned by \link[tools:userdir]{tools::R_user_dir}.} +inside the directory returned by \code{\link[tools:userdir]{tools::R_user_dir()}}.} } \value{ Invisibly returns the cache directory path.