Skip to content

Commit

Permalink
helper functions created
Browse files Browse the repository at this point in the history
  • Loading branch information
jlacko committed Oct 24, 2023
1 parent f7f9ed9 commit daa1293
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 2 deletions.
34 changes: 34 additions & 0 deletions R/helpers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' Set the local cache directory
#'
#' The function sets the environment variable RCZECHIA_HOME to be used as a local cache for RCzechia remote files; if unset tempdir() is used instead, with persistence for current session only.
#'
#' Note that when set (it is unset by default) the remote files will be cached to local file system, for good or bad. Also note that you can set the value of RCZECHIA_HOME environment variable directly, either via \code{Sys.setenv()} or via your .Rprofile.
#'
#' @param path file to be downloaded (or not...) from S3
#'
#' @return TRUE for success and FALSE for failure; returned silently

set_home <- function(path) {

if(file.access(path, mode = 2) == 0) {
Sys.setenv("RCZECHIA_HOME" = path)
invisible(TRUE)
} else {
warning("'path' not found or not writeable; default will be used instead")
invisible(FALSE)
}

}

#' Unset the local cache directory
#'
#' The function unsets the environment variable RCZECHIA_HOME, meaning tempdir() will be used in future function calls, and no persistent data will be stored locally.
#'
#' @return TRUE for success and FALSE for failure; returned silently

unset_home <- function() {

Sys.unsetenv("RCZECHIA_HOME")
invisible(TRUE)

}
2 changes: 1 addition & 1 deletion man/dot-downloader.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/dot-ok_to_proceed.Rd

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

20 changes: 20 additions & 0 deletions man/set_home.Rd

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

14 changes: 14 additions & 0 deletions man/unset_home.Rd

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

0 comments on commit daa1293

Please sign in to comment.