diff --git a/NEWS.md b/NEWS.md index c24dc96..5fc9b14 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ ## Breaking changes +* `env_exists()` now error if no argument is supplied. + ## New features ## Minor improvements and fixes diff --git a/R/env_exists.R b/R/env_exists.R index 02dd1c9..bcef65d 100644 --- a/R/env_exists.R +++ b/R/env_exists.R @@ -1,4 +1,4 @@ -#' Check If Environment Names Already exists +#' Check If Environment Already exists #' #' @inheritParams create_env #' @return Boolean. @@ -7,14 +7,15 @@ #' # Create the environment #' condathis::create_env( #' packages = "fastqc", -#' env_name = "fastqc_env" +#' env_name = "fastqc-env" #' ) #' # Check if exists -#' condathis::env_exists("fastqc_env") +#' condathis::env_exists("fastqc-env") #' #> [1] TRUE #' } #' @export -env_exists <- function(env_name = "condathis-env") { +env_exists <- function(env_name) { + rlang::check_required(env_name) available_envs <- list_envs() condathis_env_path <- env_name if (isTRUE(condathis_env_path %in% available_envs)) { diff --git a/man/env_exists.Rd b/man/env_exists.Rd index a7a6bb5..d0ec5f2 100644 --- a/man/env_exists.Rd +++ b/man/env_exists.Rd @@ -2,9 +2,9 @@ % Please edit documentation in R/env_exists.R \name{env_exists} \alias{env_exists} -\title{Check If Environment Names Already exists} +\title{Check If Environment Already exists} \usage{ -env_exists(env_name = "condathis-env") +env_exists(env_name) } \arguments{ \item{env_name}{Character. Name of the Conda environment where the packages @@ -14,17 +14,17 @@ are going to be installed. Defaults to 'condathis-env'.} Boolean. } \description{ -Check If Environment Names Already exists +Check If Environment Already exists } \examples{ \dontrun{ # Create the environment condathis::create_env( packages = "fastqc", - env_name = "fastqc_env" + env_name = "fastqc-env" ) # Check if exists -condathis::env_exists("fastqc_env") +condathis::env_exists("fastqc-env") #> [1] TRUE } } diff --git a/tests/testthat/test-env_exists.R b/tests/testthat/test-env_exists.R new file mode 100644 index 0000000..dd7b519 --- /dev/null +++ b/tests/testthat/test-env_exists.R @@ -0,0 +1,5 @@ +test_that("env_exists missing env_name", { + expect_error(env_exists()) + expect_equal(env_exists(NULL), FALSE) + expect_equal(env_exists(NA), FALSE) +}) diff --git a/tests/testthat/test-list_packages.R b/tests/testthat/test-list_packages.R new file mode 100644 index 0000000..7335ae0 --- /dev/null +++ b/tests/testthat/test-list_packages.R @@ -0,0 +1,8 @@ +test_that("list packages on absent environment", { + testthat::expect_error( + object = { + list_packages(env_name = "non-existing-env") + }, + class = "condathis_list_packages_missing_env" + ) +})