Skip to content

Commit

Permalink
Functions to inform user of correct access.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nic-Chr committed Jul 22, 2024
1 parent eef04c1 commit 04fbefd
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export(get_hscp_locality)
export(get_simd_datazone)
export(get_simd_postcode)
export(get_spd)
export(have_access)
importFrom(rlang,.data)
importFrom(tibble,tibble)
40 changes: 40 additions & 0 deletions R/access.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#' Check access to lookups
#'
#' @description
#' `have_access()` provides a convenient way to check that you have the
#' correct access to the necessary folders.
#'
#' @returns
#' `[logical(1)]` - `TRUE` if you have appropriate access and `FALSE` otherwise.
#'
#' @examples
#' \dontrun{
#' library(phslookups)
#' if (have_access()){
#' print("Success!")
#' } else {
#' print("Maybe next time")
#' }
#' }
#' @export
have_access <- function(){
read_access_to_dir(get_lookups_dir())
}
check_access <- function(fail_on_no_access = TRUE){
if (have_access()){
cli::cli_inform(c("v" = "You have the appropriate file permissions!"),
.frequency = "once",
.frequency_id = "lookup_access_inform")
} else {
no_access_msg <- c("x" = "You don't have the appropriate file permissions to {get_lookups_dir()}",
"i" = "Please raise a ServiceNow request for access to the UNIX acute dataset")
if (fail_on_no_access){
cli::cli_abort(no_access_msg)
} else {
cli::cli_warn(no_access_msg)
}
}
}
read_access_to_dir <- function(path){
file.access(path, 4) >= 0L
}
3 changes: 3 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.onLoad <- function(libname, pkgname) {
check_access(fail_on_no_access = FALSE)
}
25 changes: 25 additions & 0 deletions man/have_access.Rd

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

0 comments on commit 04fbefd

Please sign in to comment.