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

Mrc 5429 - warn on "..." specified for null driver in hipercow_init #135

Merged
merged 7 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: hipercow
Title: High Performance Computing
Version: 1.0.27
Version: 1.0.29
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Wes", "Hinsley", role = "aut"),
Expand Down
10 changes: 10 additions & 0 deletions R/root.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
##' path <- withr::local_tempfile()
##' hipercow_init(path)
hipercow_init <- function(root = ".", driver = NULL, ...) {
if ((is.null(driver)) && (length(list(...)) > 0)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps look into rlang::check_dots_used (https://rlang.r-lib.org/reference/check_dots_used.html) which might do this for us?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is the possibility of...

if (is.null(driver)) {
rlang::check_dots_empty()
}

but converting this from an error to a warning, and including a message to say why

! ... must be empty.

only applies when driver = NULL was a bit fiddly.

weshinsley marked this conversation as resolved.
Show resolved Hide resolved
args <- list(...)
cli::cli_alert_warning(
"driver was not specified, but extra args were detected: ")
ul <- cli::cli_ul()
weshinsley marked this conversation as resolved.
Show resolved Hide resolved
for (arg in names(args)) {
cli::cli_li("{arg} = {args[[arg]]}")
}
cli::cli_end(ul)
}
abs_path <- fs::path_abs(root)
norm_path <- fs::path_norm(root)
not_same_path <- (abs_path != norm_path)
Expand Down
2 changes: 1 addition & 1 deletion drivers/windows/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: hipercow.windows
Title: DIDE HPC Support for Windows
Version: 1.0.27
Version: 1.0.29
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "[email protected]"),
person("Wes", "Hinsley", role = "aut"),
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-root.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,16 @@ test_that("Report working directory if helpful", {
expect_match(msg, "Initialised hipercow at '.+'\n")

})


test_that("Extraneous args are warned about", {
path <- withr::local_tempdir()
withr::with_dir(path,
res <- testthat::evaluate_promise(
hipercow_init(potato = TRUE, turnip = 42))
)
expect_length(res$messages, 5)
expect_match(res$messages[1], "driver was not specified, but")
expect_match(res$messages[2], "potato = TRUE")
expect_match(res$messages[3], "turnip = 42")
})
Loading