diff --git a/DESCRIPTION b/DESCRIPTION index cfaf315..ac3bde6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: envsetup Title: Support the Setup of the R Environment for Clinical Trial Programming Workflows -Version: 0.2.0 +Version: 0.2.1 Authors@R: c( person("Nicholas", "Masel", email = "nmasel@its.jnj.com", role = c("aut", "cre")), person("Mike", "Stackhouse", email = "mike.stackhouse@atorusresearch.com", role = c("aut"), comment = c(ORCID = "0000-0001-6030-723X")), @@ -9,15 +9,15 @@ Authors@R: c( person("Atorus Research LLC", role = "cph") ) Description: The purpose of this package is to support the setup the R environment. - The two main features are `autos`, to automatically source files and/or - directories into your environment, and `paths` to consistently set path objects + The two main features are 'autos', to automatically source files and/or + directories into your environment, and 'paths' to consistently set path objects across projects for input and output. Both are implemented using a configuration file to allow easy, custom configurations that can be used for multiple or all projects. -License: Apache License 2.0 | file LICENSE +License: Apache License 2.0 Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Imports: config, fs, diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 223c83b..0000000 --- a/LICENSE +++ /dev/null @@ -1,13 +0,0 @@ -Copyright 2022 Janssen R&D - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/NEWS.md b/NEWS.md index b681d68..fc32219 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,11 @@ +# envsetup 0.2.1 + +- `set_autos()` will how handle NULL hierarchical paths (#66) + # envsetup 0.2.0 - `library()` will no longer actively reset autos, instead placing newly attached packages in the correct position that respects existing autos (#59) - # envsetup 0.1.0 - Minor updates to prepare for initial CRAN release (#55) diff --git a/R/autos.R b/R/autos.R index 37b30b8..4be213d 100644 --- a/R/autos.R +++ b/R/autos.R @@ -24,6 +24,11 @@ set_autos <- function(autos, envsetup_environ = Sys.getenv("ENVSETUP_ENVIRON")) stop("Paths for autos in your envsetup configuration file must be named", call.=FALSE) } + # remove NULL before further processing + # NULL is expected for hierarchical paths when running in an environment + # after the first level of the hierarchy + autos <- autos[!vapply(autos, is.null, FALSE)] + for (i in seq_along(autos)) { cur_autos <- autos[[i]] @@ -291,4 +296,4 @@ library <- function(..., pos = NULL) { pos <- min(grep("^package:", search())) } base::library(..., pos = pos) -} \ No newline at end of file +} diff --git a/R/init.R b/R/init.R index b12bdfa..f701308 100644 --- a/R/init.R +++ b/R/init.R @@ -1,6 +1,6 @@ #' Initialize the R environment with envsetup #' -#' @param project Character. The path to the project directory. Defaults to the current working directory. +#' @param project Character. The path to the project directory. #' @param config_path Character. The path of the config file. Defaults to NULL. #' @param create_paths Logical indicating if missing paths should be created. Defaults to NULL. #' @export @@ -36,7 +36,7 @@ #' init(project = tmpdir, #' config_path = file.path(tmpdir, "hierarchy.yml"), #' create_paths = TRUE) -init <- function(project = getwd(), config_path = NULL, create_paths = NULL) { +init <- function(project, config_path = NULL, create_paths = NULL) { create_config <- FALSE config_found <- FALSE diff --git a/cran-comments.md b/cran-comments.md index 368ba59..4587b05 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,3 +1,10 @@ +## Resubmission +This is a resubmission. In this version I have: + +* Corrected quotations in the description. +* Removed the LICENSE file, as there are no additional restrictions. +* Removed the default write path in R/init.R. + ## envsetup 0.1.0 Tested on RHEL 7, RHEL 8, GitHub Action and RHub. diff --git a/man/init.Rd b/man/init.Rd index 4595308..293f5e0 100644 --- a/man/init.Rd +++ b/man/init.Rd @@ -4,10 +4,10 @@ \alias{init} \title{Initialize the R environment with envsetup} \usage{ -init(project = getwd(), config_path = NULL, create_paths = NULL) +init(project, config_path = NULL, create_paths = NULL) } \arguments{ -\item{project}{Character. The path to the project directory. Defaults to the current working directory.} +\item{project}{Character. The path to the project directory.} \item{config_path}{Character. The path of the config file. Defaults to NULL.} diff --git a/tests/testthat/_snaps/R4.2/autos.md b/tests/testthat/_snaps/R4.2/autos.md index 8797947..018ac22 100644 --- a/tests/testthat/_snaps/R4.2/autos.md +++ b/tests/testthat/_snaps/R4.2/autos.md @@ -2,6 +2,7 @@ Code suppressMessages(rprofile(custom_name)) - Warning + Condition + Warning: The projects autos has named environments DEV, QA, PROD that do not match with the envsetup_environ parameter or ENVSETUP_ENVIRON environment variable bad_name diff --git a/tests/testthat/_snaps/R4.2/init.md b/tests/testthat/_snaps/R4.2/init.md index 8773ae3..55cdbd6 100644 --- a/tests/testthat/_snaps/R4.2/init.md +++ b/tests/testthat/_snaps/R4.2/init.md @@ -2,7 +2,7 @@ Code init(init_tmpdir, config_path, create_paths = FALSE) - Message + Message v Configuration file found! i The following paths in your configuration do not exist: /DEV/username/project1/data @@ -21,7 +21,7 @@ Code init(init_tmpdir, config_path, create_paths = FALSE) - Message + Message v Configuration file found! i The following paths in your configuration do not exist: /DEV/username/project1/data @@ -40,7 +40,7 @@ Code init(init_tmpdir, config_path, create_paths = FALSE) - Message + Message v Configuration file found! i The following paths in your configuration do not exist: /DEV/username/project1/data diff --git a/tests/testthat/_snaps/R4.4/autos.md b/tests/testthat/_snaps/R4.4/autos.md new file mode 100644 index 0000000..018ac22 --- /dev/null +++ b/tests/testthat/_snaps/R4.4/autos.md @@ -0,0 +1,8 @@ +# Autos warns user when ENVSETUP_ENVIRON does not match named environments in autos + + Code + suppressMessages(rprofile(custom_name)) + Condition + Warning: + The projects autos has named environments DEV, QA, PROD that do not match with the envsetup_environ parameter or ENVSETUP_ENVIRON environment variable bad_name + diff --git a/tests/testthat/_snaps/R4.4/init.md b/tests/testthat/_snaps/R4.4/init.md new file mode 100644 index 0000000..55cdbd6 --- /dev/null +++ b/tests/testthat/_snaps/R4.4/init.md @@ -0,0 +1,57 @@ +# init creates a .Rprofile + + Code + init(init_tmpdir, config_path, create_paths = FALSE) + Message + v Configuration file found! + i The following paths in your configuration do not exist: + /DEV/username/project1/data + /PROD/project1/data + /DEV/username/project1/programs + /PROD/project1/programs + /DEV/username/project1/functions + /PROD/project1/functions + /DEV/username/project1/output + /PROD/project1/output + i All path objects will not work since directories are missing. + v .Rprofile created + v envsetup initialization complete + +# init initializes an .Rprofile correcty when one does not exist + + Code + init(init_tmpdir, config_path, create_paths = FALSE) + Message + v Configuration file found! + i The following paths in your configuration do not exist: + /DEV/username/project1/data + /PROD/project1/data + /DEV/username/project1/programs + /PROD/project1/programs + /DEV/username/project1/functions + /PROD/project1/functions + /DEV/username/project1/output + /PROD/project1/output + i All path objects will not work since directories are missing. + v .Rprofile created + v envsetup initialization complete + +# init initializes an .Rprofile correcty when one does exist + + Code + init(init_tmpdir, config_path, create_paths = FALSE) + Message + v Configuration file found! + i The following paths in your configuration do not exist: + /DEV/username/project1/data + /PROD/project1/data + /DEV/username/project1/programs + /PROD/project1/programs + /DEV/username/project1/functions + /PROD/project1/functions + /DEV/username/project1/output + /PROD/project1/output + i All path objects will not work since directories are missing. + v .Rprofile updated + v envsetup initialization complete + diff --git a/tests/testthat/_snaps/utils.md b/tests/testthat/_snaps/utils.md index a86bffa..ff7f94e 100644 --- a/tests/testthat/_snaps/utils.md +++ b/tests/testthat/_snaps/utils.md @@ -2,7 +2,7 @@ Code validate_config(config::get(file = path)) - Message + Message v paths are specified as part of your configuration i no hierarchical paths found @@ -10,7 +10,7 @@ Code validate_config(config::get(file = path)) - Message + Message v paths are specified as part of your configuration v hierarchal paths found for: data @@ -21,7 +21,7 @@ Code validate_config(config::get(file = path)) - Message + Message v paths are specified as part of your configuration v hierarchal paths found for: data @@ -35,6 +35,6 @@ Code validate_config(config::get(file = path)) - Message + Message i no paths are specified as part of your configuration, skipping path valiation diff --git a/tests/testthat/man/_envsetup_testthat_null.yml b/tests/testthat/man/_envsetup_testthat_null.yml new file mode 100644 index 0000000..8a2cb1d --- /dev/null +++ b/tests/testthat/man/_envsetup_testthat_null.yml @@ -0,0 +1,33 @@ +default: + project_path: !expr Sys.setenv(ENVSETUP_PROJECT_PATH = Sys.getenv("testpath")); + Sys.getenv("testpath") + paths: + data: !expr list( + DEV = file.path(Sys.getenv("ENVSETUP_PROJECT_PATH"), "DEV", "data"), + QA = file.path(Sys.getenv("ENVSETUP_PROJECT_PATH"), "QA", "data"), + PROD = file.path(Sys.getenv("ENVSETUP_PROJECT_PATH"), "PROD", "data") + ) + programs: !expr list( + DEV = file.path(Sys.getenv("ENVSETUP_PROJECT_PATH"), "DEV", "programs"), + QA = file.path(Sys.getenv("ENVSETUP_PROJECT_PATH"), "QA", "programs"), + PROD = file.path(Sys.getenv("ENVSETUP_PROJECT_PATH"), "PROD", "programs") + ) + functions: !expr list( + DEV = file.path(Sys.getenv("ENVSETUP_PROJECT_PATH"), "DEV", "functions"), + QA = file.path(Sys.getenv("ENVSETUP_PROJECT_PATH"), "QA", "functions"), + PROD = file.path(Sys.getenv("ENVSETUP_PROJECT_PATH"), "PROD", "functions") + ) + output: !expr list( + DEV = file.path(Sys.getenv("ENVSETUP_PROJECT_PATH"), "DEV", "output"), + QA = file.path(Sys.getenv("ENVSETUP_PROJECT_PATH"), "QA", "output"), + PROD = file.path(Sys.getenv("ENVSETUP_PROJECT_PATH"), "PROD", "output") + ) + autos: + projects: !expr NULL + global: !expr file.path(Sys.getenv("ENVSETUP_PROJECT_PATH"), "global", "functions") + envre: !expr file.path( + Sys.getenv("ENVSETUP_PROJECT_PATH"), + "PROD", + "functions", + "envre.R" + ) diff --git a/tests/testthat/test-autos.R b/tests/testthat/test-autos.R index 52ea3bb..93b7581 100644 --- a/tests/testthat/test-autos.R +++ b/tests/testthat/test-autos.R @@ -8,6 +8,7 @@ file.copy(testthat::test_path("man/testdir/DEV"), tmpdir, recursive = TRUE) file.copy(testthat::test_path("man/testdir/global"), tmpdir, recursive = TRUE) file.copy(testthat::test_path("man/testdir/PROD"), tmpdir, recursive = TRUE) file.copy(testthat::test_path("man/testdir/QA"), tmpdir, recursive = TRUE) +dir.create(file.path(tmpdir, "returns_null")) custom_name <- config::get( file = testthat::test_path("man/_envsetup_testthat.yml") @@ -125,3 +126,15 @@ test_that("Autos warns user when ENVSETUP_ENVIRON does not match named environme expect_snapshot(suppressMessages(rprofile(custom_name)), variant = r_version()) }) + + +#' @editor Nick Masel +#' @editDate 2024-10-24 +detach_autos() +Sys.setenv(ENVSETUP_ENVIRON = "QA") +null_test <- config::get( + file = testthat::test_path("man/_envsetup_testthat_null.yml") +) +test_that("NULL paths do not throw an error", { + expect_no_error(set_autos(null_test$autos)) +})