Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #66: remove nulls before setting autos #67

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", role = c("aut", "cre")),
person("Mike", "Stackhouse", email = "[email protected]", role = c("aut"), comment = c(ORCID = "0000-0001-6030-723X")),
Expand All @@ -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,
Expand Down
13 changes: 0 additions & 13 deletions LICENSE

This file was deleted.

5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
7 changes: 6 additions & 1 deletion R/autos.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

Expand Down Expand Up @@ -291,4 +296,4 @@ library <- function(..., pos = NULL) {
pos <- min(grep("^package:", search()))
}
base::library(..., pos = pos)
}
}
4 changes: 2 additions & 2 deletions R/init.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions man/init.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion tests/testthat/_snaps/R4.2/autos.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Code
suppressMessages(rprofile(custom_name))
Warning <simpleWarning>
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

6 changes: 3 additions & 3 deletions tests/testthat/_snaps/R4.2/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Code
init(init_tmpdir, config_path, create_paths = FALSE)
Message <rlang_message>
Message
v Configuration file found!
i The following paths in your configuration do not exist:
/DEV/username/project1/data
Expand All @@ -21,7 +21,7 @@

Code
init(init_tmpdir, config_path, create_paths = FALSE)
Message <rlang_message>
Message
v Configuration file found!
i The following paths in your configuration do not exist:
/DEV/username/project1/data
Expand All @@ -40,7 +40,7 @@

Code
init(init_tmpdir, config_path, create_paths = FALSE)
Message <rlang_message>
Message
v Configuration file found!
i The following paths in your configuration do not exist:
/DEV/username/project1/data
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/R4.4/autos.md
Original file line number Diff line number Diff line change
@@ -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

57 changes: 57 additions & 0 deletions tests/testthat/_snaps/R4.4/init.md
Original file line number Diff line number Diff line change
@@ -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

8 changes: 4 additions & 4 deletions tests/testthat/_snaps/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

Code
validate_config(config::get(file = path))
Message <rlang_message>
Message
v paths are specified as part of your configuration
i no hierarchical paths found

# validate_config, hierarchy paths return correct messages

Code
validate_config(config::get(file = path))
Message <rlang_message>
Message
v paths are specified as part of your configuration
v hierarchal paths found for:
data
Expand All @@ -21,7 +21,7 @@

Code
validate_config(config::get(file = path))
Message <rlang_message>
Message
v paths are specified as part of your configuration
v hierarchal paths found for:
data
Expand All @@ -35,6 +35,6 @@

Code
validate_config(config::get(file = path))
Message <rlang_message>
Message
i no paths are specified as part of your configuration, skipping path valiation

33 changes: 33 additions & 0 deletions tests/testthat/man/_envsetup_testthat_null.yml
Original file line number Diff line number Diff line change
@@ -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"
)
13 changes: 13 additions & 0 deletions tests/testthat/test-autos.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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))
})