Skip to content

Commit

Permalink
formats style
Browse files Browse the repository at this point in the history
  • Loading branch information
sellorm committed May 2, 2023
1 parent 6d26ed9 commit 5a62a8a
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 27 deletions.
10 changes: 7 additions & 3 deletions R/check_rstudio.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ check_ping_endpoint <- function(url) {
request <- httr2::request(ping_url)
result <- tryCatch(
httr2::req_perform(request),
error = function(e) {list(message = "Request failure", status_code = 0)}
)
error = function(e) {
list(message = "Request failure", status_code = 0)
}
)
result_body <- tryCatch(
httr2::resp_body_json(result, check_type = FALSE),
error = function(e) {list(message = "Problem with result", status_code = 0)}
error = function(e) {
list(message = "Problem with result", status_code = 0)
}
)
if ((result$status_code == 200) & (is.list(result_body))) {
TRUE
Expand Down
12 changes: 6 additions & 6 deletions R/sitrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ sitrep <- function(silent = FALSE, path = "~/.envstat") {
"envstat situation report"
)

envstatconf <- read_config(path = path)
envstatconf <- read_config(path = path)

output_files <- check_files(envstatconf, silent = silent)
output_dirs <- check_dirs(envstatconf, silent = silent)
output_files <- check_files(envstatconf, silent = silent)
output_dirs <- check_dirs(envstatconf, silent = silent)
output_env_vars <- check_env_vars(envstatconf, silent = silent)
output_rspm <- check_rspm(envstatconf, silent = silent)
output_rsc <- check_rsc(envstatconf, silent = silent)
output_repos <- check_repos_available(envstatconf, silent = silent)
output_rspm <- check_rspm(envstatconf, silent = silent)
output_rsc <- check_rsc(envstatconf, silent = silent)
output_repos <- check_repos_available(envstatconf, silent = silent)

all_outputs <- c(
output_files,
Expand Down
22 changes: 13 additions & 9 deletions R/use_envstat.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use_envstat <- function(filepath = "~/.envstat", source = NULL, consent = FALSE)
}

# Do we have user consent?
if (!isTRUE(user_consent(provided = consent, path = filepath))){
if (!isTRUE(user_consent(provided = consent, path = filepath))) {
stop("This function requires user consent. Please try again.")
}

Expand Down Expand Up @@ -67,18 +67,22 @@ use_envstat <- function(filepath = "~/.envstat", source = NULL, consent = FALSE)
#' # But you can tell it to use a different config file if you prefer
#' envstat::edit_envstat(filepath = "/tmp/config.yml")
#' }
edit_envstat <- function(filepath = "~/.envstat"){
if (!interactive()){
stop("The current session is not interactive.\n",
"You can only use this function from an interactive R session.")
edit_envstat <- function(filepath = "~/.envstat") {
if (!interactive()) {
stop(
"The current session is not interactive.\n",
"You can only use this function from an interactive R session."
)
}

if (!file.exists(filepath)){
stop("Can't find file: ", filepath, "\n",
"Please check the supplied path and try again.")
if (!file.exists(filepath)) {
stop(
"Can't find file: ", filepath, "\n",
"Please check the supplied path and try again."
)
}

if (rstudioapi::isAvailable()){
if (rstudioapi::isAvailable()) {
rstudioapi::navigateToFile(filepath)
} else {
utils::file.edit(filepath)
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ user_consent <- function(provided = FALSE, path = "~/.envstat") {
return(TRUE)
}

# If the user has specified their own path we can assume they consent
# If the user has specified their own path we can assume they consent
if (!path == "~/.envstat") {
return(TRUE)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-check_env_vars.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("check environment variable chacking works", {
# Set an environment variable to test
Sys.setenv("ENVSTAT_TEST"="hatstand")
Sys.setenv("ENVSTAT_TEST" = "hatstand")

# Load a custom config to test the env var
config <- list(env_vars = c("ENVSTAT_TEST"))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-repos_available.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
r <- getOption("repos")
r["CRAN"] <- "https://cran.r-project.org"
r["RSPM"] <- "https://packagemanager.rstudio.com/cran/latest"
options(repos=r)
options(repos = r)

test_that("check repo checking works", {
# Tell envstat to not check if repos are available
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-sitrep.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("test sitrep works", {
Sys.setenv("TEST_ENV_VAR"="set")
Sys.setenv("TEST_ENV_VAR" = "set")
expect_true(sitrep(silent = TRUE, path = "./test-conf.envstat"))
Sys.unsetenv("TEST_ENV_VAR")
})
10 changes: 6 additions & 4 deletions tests/testthat/test-use_envstat.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ test_that("check use_envstat works", {
# write the config to a temporary file
temp_file <- tempfile()
testthat::expect_true(
envstat::use_envstat(filepath = temp_file,
source = "./test-conf.envstat",
consent = TRUE))
envstat::use_envstat(
filepath = temp_file,
source = "./test-conf.envstat",
consent = TRUE
)
)

# Read our new config file
config <- envstat:::read_config(temp_file)
Expand All @@ -15,4 +18,3 @@ test_that("check use_envstat works", {
# Clean up after ourselves
file.remove(temp_file)
})

2 changes: 1 addition & 1 deletion tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test_that("User consent is properly handled", {
testthat::expect_true(envstat:::user_consent(provided = TRUE))

# User consent override via environment variable
Sys.setenv("ENVSTAT"="OVERRIDE")
Sys.setenv("ENVSTAT" = "OVERRIDE")
testthat::expect_true(envstat:::user_consent())
Sys.unsetenv("ENVSTAT")

Expand Down

0 comments on commit 5a62a8a

Please sign in to comment.