Skip to content

Commit

Permalink
Closes #2184 check _keys renaming scheme (#2200)
Browse files Browse the repository at this point in the history
* feat: #2184 rename check_keys

* chore: #2184 cleanup news

* code typo

* styler/lintr

* feat: #2184 add appropriate deprecation test

---------

Co-authored-by: Zelos Zhu <[email protected]>
Co-authored-by: Ben Straub <[email protected]>
  • Loading branch information
3 people authored Nov 7, 2023
1 parent 214c835 commit 708d232
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ for the event number, which can be used in `order`. (#2140)

- The default value for the `false_value` argument in `derive_extreme_records()` was changed to `NA_character_` (#2125)

- For the function `consolidate_metadata()`, the argument `check_keys` was renamed to `check_type` to align with other functions (#2184)

- In `filter_joined()` and `derive_var_joined_exist_flag()` (#2126)
- the `first_cond` argument was deprecated in favor of `first_cond_upper` and
- the `filter` argument was deprecated in favor of `filter_join`.
Expand Down
32 changes: 28 additions & 4 deletions R/consolidate_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@
#'
#' @param check_keys Check keys?
#'
#' `r lifecycle::badge("deprecated")` Please use `check_type` instead.
#'
#' If `"warning"` or `"error"` is specified, a message is issued if the key
#' variables (`key_vars`) are not a unique key in all of the input datasets
#' (`datasets`).
#'
#' *Permitted Values*: `"none"`, `"warning"`, `"error"`
#'
#' @param check_type Check uniqueness?
#'
#' If `"warning"` or `"error"` is specified, a message is issued if the key
#' variables (`key_vars`) are not a unique key in all of the input datasets
#' (`datasets`).
#'
#' *Permitted Values*: `"none"`, `"warning"`, `"error"`
#'
#' @details All observations of the input datasets are put together into a
#' single dataset. If a by group (defined by `key_vars`) exists in more than
Expand Down Expand Up @@ -80,7 +89,8 @@ consolidate_metadata <- function(datasets,
key_vars,
source_var = SOURCE,
check_vars = "warning",
check_keys = "error") {
check_keys,
check_type = "error") {
assert_list_of(datasets, class = "data.frame", named = TRUE)
assert_vars(key_vars)
source_var <- assert_symbol(enexpr(source_var))
Expand All @@ -90,9 +100,23 @@ consolidate_metadata <- function(datasets,
values = c("none", "message", "warning", "error"),
case_sensitive = FALSE
)
check_keys <-
if (!is_missing(check_keys)) {
deprecate_warn(
"1.0.0",
"consolidate_metadata(check_keys = )",
"consolidate_metadata(check_type = )"
)
check_type <-
assert_character_scalar(
check_keys,
values = c("none", "warning", "error"),
case_sensitive = FALSE,
optional = TRUE
)
}
check_type <-
assert_character_scalar(
check_keys,
check_type,
values = c("none", "warning", "error"),
case_sensitive = FALSE
)
Expand All @@ -118,7 +142,7 @@ consolidate_metadata <- function(datasets,
by_vars = key_vars,
order = exprs(!!tmp_source_ord),
mode = "last",
check_type = check_keys
check_type = check_type
) %>%
remove_tmp_vars()
}
13 changes: 12 additions & 1 deletion man/consolidate_metadata.Rd

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

34 changes: 32 additions & 2 deletions tests/testthat/test-consolidate_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,38 @@ test_that("consolidate_metadata Test 2: error if key vars are not unique", {
)
})

## Test 3: warn if variables differ ----
test_that("consolidate_metadata Test 3: warn if variables differ", {

## Test 3: check_keys deprecation test ----
test_that("consolidate_metadata Test 3: check_keys deprecation test", {
glob <- tibble::tribble(
~id, ~val,
1, "glob_val_1a",
1, "glob_val_1b",
2, "glob_val_2"
)
stud <- tibble::tribble(
~id, ~val,
3, "stud_val_3"
)

expect_warning(
try(
consolidate_metadata(
datasets = list(
global = glob,
study = stud
),
key_vars = exprs(id),
check_keys = "error"
),
silent = TRUE
),
class = "lifecycle_warning_deprecated"
)
})

## Test 4: warn if variables differ ----
test_that("consolidate_metadata Test 4: warn if variables differ", {
glob <- tibble::tribble(
~id, ~val,
1, "glob_val_1",
Expand Down

0 comments on commit 708d232

Please sign in to comment.