Skip to content

Commit

Permalink
updates to galah_config()
Browse files Browse the repository at this point in the history
- add deprecation message for argument `cache_directory`
- support recursive directory generation
- update tests
  • Loading branch information
mjwestgate committed Nov 15, 2023
1 parent d8d1a95 commit 7f78e12
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ check_directory <- function(x){
}else{
directory <- dirname(x)
if(!dir.exists(directory)){
dir.create(directory)
dir.create(directory, recursive = TRUE)
}else{
x
}
Expand Down
4 changes: 2 additions & 2 deletions R/deprecated_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#' atlas_taxonomy()
#' }
#' @rdname deprecated-functions
#' @importFrom rlang warn
#' @importFrom lifecycle deprecate_warn
#' @export
galah_down_to <- function(...){

lifecycle::deprecate_warn(when = "2.0.0",
deprecate_warn(when = "2.0.0",
what = "galah_down_to()",
details = "Use `filter(rank == \"chosen_rank\")` instead."
)
Expand Down
14 changes: 14 additions & 0 deletions R/galah_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
#' # Make debugging in your session easier by setting `verbose = TRUE`
#' galah_config(verbose = TRUE)
#' }
#' @importFrom lifecycle deprecate_warn
#' @importFrom glue glue
#' @importFrom rlang abort
#' @importFrom potions brew
#' @importFrom potions pour
Expand All @@ -80,6 +82,18 @@ galah_config <- function(...) {

# add user-provided information
if(length(dots) > 0){

# check for deprecated `cache_directory`
if(any(names(dots) == "cache_directory")){
dots_location <- which(names(dots) == "cache_directory")
value <- dots$cache_directory
deprecate_warn(when = "2.0.0",
what = "galah_config(cache_directory)",
details = glue("Use `galah_config(directory = \"{value}\")` instead.")
)
names(dots)[dots_location] <- "directory"
}

# check all values in dots to ensure they are named
if(length(dots) != length(names(dots))){
bullets <- c("All arguments to `galah_config() must be named.",
Expand Down
16 changes: 15 additions & 1 deletion tests/testthat/test-galah_config.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
test_that("galah_config warns that `cache_directory` is deprecated", {
dir.create("temp")
expect_warning(galah_config(cache_directory = "temp"))
expect_true(galah_config()$package$directory == "temp")
galah_config(directory = tempfile())
unlink("temp", recursive = TRUE)
})

test_that("galah_config creates nested folders where requested", {
galah_config(directory = "non/existent/dir")
expect_true(any(grepl("./non", list.dirs())))
galah_config(directory = tempfile())
unlink("non", recursive = TRUE)
})

test_that("galah_config checks download_id", {
skip_if_offline()
galah_config(verbose = TRUE)
Expand All @@ -14,7 +29,6 @@ test_that("galah_config checks inputs", {
expect_error(galah_config(caching = "value"))
expect_error(galah_config(verbose = "value"))
expect_error(galah_config(email = 4))
expect_error(galah_config(cache_directory = "non/existent/dir"))
expect_error(galah_config(bad_option = "value"))
expect_error(galah_config(atlas = "world"))
expect_silent(galah_config(verbose = FALSE, atlas = "Australia"))
Expand Down

0 comments on commit 7f78e12

Please sign in to comment.