From 04fbefd43bd10cde0c91bdf28039fefddbf2243d Mon Sep 17 00:00:00 2001 From: nicolc11 Date: Mon, 22 Jul 2024 14:47:44 +0100 Subject: [PATCH 1/4] Functions to inform user of correct access. --- NAMESPACE | 1 + R/access.R | 40 ++++++++++++++++++++++++++++++++++++++++ R/zzz.R | 3 +++ man/have_access.Rd | 25 +++++++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 R/access.R create mode 100644 R/zzz.R create mode 100644 man/have_access.Rd diff --git a/NAMESPACE b/NAMESPACE index afd9c7d..9c9f483 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/access.R b/R/access.R new file mode 100644 index 0000000..faca565 --- /dev/null +++ b/R/access.R @@ -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 +} diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..57ef744 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,3 @@ +.onLoad <- function(libname, pkgname) { + check_access(fail_on_no_access = FALSE) +} diff --git a/man/have_access.Rd b/man/have_access.Rd new file mode 100644 index 0000000..a41237c --- /dev/null +++ b/man/have_access.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/access.R +\name{have_access} +\alias{have_access} +\title{Check access to lookups} +\usage{ +have_access() +} +\value{ +\verb{[logical(1)]} - \code{TRUE} if you have appropriate access and \code{FALSE} otherwise. +} +\description{ +\code{have_access()} provides a convenient way to check that you have the +correct access to the necessary folders. +} +\examples{ +\dontrun{ + library(phslookups) + if (have_access()){ + print("Success!") + } else { + print("Maybe next time") + } +} +} From ecba78f1d7ad74de025e3c8158675a406209f34c Mon Sep 17 00:00:00 2001 From: Nic-Chr Date: Mon, 22 Jul 2024 14:03:23 +0000 Subject: [PATCH 2/4] Style code (GHA) --- R/access.R | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/R/access.R b/R/access.R index faca565..d2a86e0 100644 --- a/R/access.R +++ b/R/access.R @@ -9,32 +9,35 @@ #' #' @examples #' \dontrun{ -#' library(phslookups) -#' if (have_access()){ -#' print("Success!") -#' } else { -#' print("Maybe next time") -#' } +#' library(phslookups) +#' if (have_access()) { +#' print("Success!") +#' } else { +#' print("Maybe next time") +#' } #' } #' @export -have_access <- function(){ +have_access <- function() { read_access_to_dir(get_lookups_dir()) } -check_access <- function(fail_on_no_access = TRUE){ - if (have_access()){ +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") + .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){ + 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){ +read_access_to_dir <- function(path) { file.access(path, 4) >= 0L } From d20a58568dd0dde803d7fe4976717e466e4b58fc Mon Sep 17 00:00:00 2001 From: nicolc11 Date: Wed, 24 Jul 2024 15:51:26 +0100 Subject: [PATCH 3/4] Updates. --- NAMESPACE | 1 - R/access.R | 31 ++----------------------------- man/have_access.Rd | 25 ------------------------- 3 files changed, 2 insertions(+), 55 deletions(-) delete mode 100644 man/have_access.Rd diff --git a/NAMESPACE b/NAMESPACE index 9c9f483..afd9c7d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,5 @@ export(get_hscp_locality) export(get_simd_datazone) export(get_simd_postcode) export(get_spd) -export(have_access) importFrom(rlang,.data) importFrom(tibble,tibble) diff --git a/R/access.R b/R/access.R index d2a86e0..0394e69 100644 --- a/R/access.R +++ b/R/access.R @@ -1,32 +1,8 @@ -#' 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()) + file.access(get_lookups_dir(), 4) >= 0L } 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 { + if (!have_access()) { 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" @@ -38,6 +14,3 @@ check_access <- function(fail_on_no_access = TRUE) { } } } -read_access_to_dir <- function(path) { - file.access(path, 4) >= 0L -} diff --git a/man/have_access.Rd b/man/have_access.Rd deleted file mode 100644 index a41237c..0000000 --- a/man/have_access.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/access.R -\name{have_access} -\alias{have_access} -\title{Check access to lookups} -\usage{ -have_access() -} -\value{ -\verb{[logical(1)]} - \code{TRUE} if you have appropriate access and \code{FALSE} otherwise. -} -\description{ -\code{have_access()} provides a convenient way to check that you have the -correct access to the necessary folders. -} -\examples{ -\dontrun{ - library(phslookups) - if (have_access()){ - print("Success!") - } else { - print("Maybe next time") - } -} -} From e3a9f515d9ed964e1730072423b3f76321b7db0b Mon Sep 17 00:00:00 2001 From: nicolc11 Date: Wed, 24 Jul 2024 15:56:33 +0100 Subject: [PATCH 4/4] Renamed function. --- R/access.R | 2 +- R/zzz.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/access.R b/R/access.R index 0394e69..9dbe4d3 100644 --- a/R/access.R +++ b/R/access.R @@ -1,7 +1,7 @@ have_access <- function() { file.access(get_lookups_dir(), 4) >= 0L } -check_access <- function(fail_on_no_access = TRUE) { +check_lookups_access <- function(fail_on_no_access = TRUE) { if (!have_access()) { no_access_msg <- c( "x" = "You don't have the appropriate file permissions to {get_lookups_dir()}", diff --git a/R/zzz.R b/R/zzz.R index 57ef744..b62ae3a 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,3 +1,3 @@ .onLoad <- function(libname, pkgname) { - check_access(fail_on_no_access = FALSE) + check_lookups_access(fail_on_no_access = FALSE) }