From daa129337add4d911523089683eed38266b0e6fd Mon Sep 17 00:00:00 2001 From: Jindra Lacko Date: Tue, 24 Oct 2023 23:48:14 +0200 Subject: [PATCH] helper functions created --- R/helpers.R | 34 ++++++++++++++++++++++++++++++++++ man/dot-downloader.Rd | 2 +- man/dot-ok_to_proceed.Rd | 2 +- man/set_home.Rd | 20 ++++++++++++++++++++ man/unset_home.Rd | 14 ++++++++++++++ 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 R/helpers.R create mode 100644 man/set_home.Rd create mode 100644 man/unset_home.Rd diff --git a/R/helpers.R b/R/helpers.R new file mode 100644 index 0000000..000cee7 --- /dev/null +++ b/R/helpers.R @@ -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) + +} diff --git a/man/dot-downloader.Rd b/man/dot-downloader.Rd index cd54cc5..5b75847 100644 --- a/man/dot-downloader.Rd +++ b/man/dot-downloader.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/downloader.R +% Please edit documentation in R/internals.R \name{.downloader} \alias{.downloader} \title{Internal function - generic downloader, used to serve the rds files from S3} diff --git a/man/dot-ok_to_proceed.Rd b/man/dot-ok_to_proceed.Rd index e484915..e4f0092 100644 --- a/man/dot-ok_to_proceed.Rd +++ b/man/dot-ok_to_proceed.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ok_to_proceed.R +% Please edit documentation in R/internals.R \name{.ok_to_proceed} \alias{.ok_to_proceed} \title{Internal function - tests availability of internet resources} diff --git a/man/set_home.Rd b/man/set_home.Rd new file mode 100644 index 0000000..f00d1bc --- /dev/null +++ b/man/set_home.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/helpers.R +\name{set_home} +\alias{set_home} +\title{Set the local cache directory} +\usage{ +set_home(path) +} +\arguments{ +\item{path}{file to be downloaded (or not...) from S3} +} +\value{ +TRUE for success and FALSE for failure; returned silently +} +\description{ +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. +} +\details{ +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. +} diff --git a/man/unset_home.Rd b/man/unset_home.Rd new file mode 100644 index 0000000..6e6299f --- /dev/null +++ b/man/unset_home.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/helpers.R +\name{unset_home} +\alias{unset_home} +\title{Unset the local cache directory} +\usage{ +unset_home() +} +\value{ +TRUE for success and FALSE for failure; returned silently +} +\description{ +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. +}