Skip to content

Commit

Permalink
Merge pull request #1824 from pharmaverse/pre-release
Browse files Browse the repository at this point in the history
Release v0.10.1
  • Loading branch information
zdz2101 authored Mar 15, 2023
2 parents ff6b8cf + 8602d12 commit 6dead5a
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 39 deletions.
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: admiral
Type: Package
Title: ADaM in R Asset Library
Version: 0.10.0
Version: 0.10.1
Authors@R: c(
person("Thomas", "Neitmann", email = "[email protected]", role = c("aut", "cre")),
person("Stefan", "Bundfuss", role = "aut"),
Expand Down Expand Up @@ -29,6 +29,9 @@ Authors@R: c(
person("Zelos", "Zhu", role = "aut"),
person("Jeffrey", "Dickinson", role = "aut"),
person("Ania", "Golab", role = "aut"),
person("Kangjie", "Zhang", role = "aut"),
person("Daphne", "Grasselly", role = "aut"),
person("Adam", "Forys", role = "aut"),
person("Michael", "Thorpe", role = "ctb"),
person("Declan", "Hodges", role = "ctb"),
person("Jaxon", "Abercrombie", role = "ctb"),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# admiral 0.10.1

- Fix checks on `derive_vars_dtm()` and `derive_vars_dt()`
that were too restrictive. (#1810)

# admiral 0.10.0

## New Features
Expand Down
24 changes: 14 additions & 10 deletions R/derive_date_vars.R
Original file line number Diff line number Diff line change
Expand Up @@ -1395,12 +1395,14 @@ derive_vars_dt <- function(dataset,
(highest_imputation == "Y" & length(min_dates) == 0 & length(max_dates) == 0)) {
abort("If `highest_impuation` = \"Y\" is specified, `min_dates` or `max_dates` should be specified respectively.") # nolint
}

if (highest_imputation == "Y" & !is.null(min_dates) & date_imputation != "first") {
warning("If `highest_impuation` = \"Y\" and `min_dates` is specified, `date_imputation` should be set to \"first\".") # nolint
if (highest_imputation == "Y") {
assert_character_scalar(date_imputation, values = c("first", "last"))
}
if (highest_imputation == "Y" & is.null(min_dates) & date_imputation == "first") {
warning("If `highest_impuation` = \"Y\" and `date_imputation` = \"first\" is specified, `min_dates` should be specified.") # nolint
}
if (highest_imputation == "Y" & !is.null(max_dates) & date_imputation != "last") {
warning("If `highest_impuation` = \"Y\" and `max_dates` is specified, `date_imputation` should be set to \"last\".") # nolint
if (highest_imputation == "Y" & is.null(max_dates) & date_imputation == "last") {
warning("If `highest_impuation` = \"Y\" and `date_imputation` = \"last\" is specified, `max_dates` should be specified.") # nolint
}

# output varname
Expand Down Expand Up @@ -1591,12 +1593,14 @@ derive_vars_dtm <- function(dataset,
(highest_imputation == "Y" & length(min_dates) == 0 & length(max_dates) == 0)) {
abort("If `highest_impuation` = \"Y\" is specified, `min_dates` or `max_dates` should be specified respectively.") # nolint
}

if (highest_imputation == "Y" & !is.null(min_dates) & date_imputation != "first") {
warning("If `highest_impuation` = \"Y\" and `min_dates` is specified, `date_imputation` should be set to \"first\".") # nolint
if (highest_imputation == "Y") {
assert_character_scalar(date_imputation, values = c("first", "last"))
}
if (highest_imputation == "Y" & is.null(min_dates) & date_imputation == "first") {
warning("If `highest_impuation` = \"Y\" and `date_imputation` = \"first\" is specified, `min_dates` should be specified.") # nolint
}
if (highest_imputation == "Y" & !is.null(max_dates) & date_imputation != "last") {
warning("If `highest_impuation` = \"Y\" and `max_dates` is specified, `date_imputation` should be set to \"last\".") # nolint
if (highest_imputation == "Y" & is.null(max_dates) & date_imputation == "last") {
warning("If `highest_impuation` = \"Y\" and `date_imputation` = \"last\" is specified, `max_dates` should be specified.") # nolint
}

dtm <- paste0(new_vars_prefix, "DTM")
Expand Down
3 changes: 3 additions & 0 deletions man/admiral-package.Rd

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

112 changes: 84 additions & 28 deletions tests/testthat/test-derive_date_vars.R
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ test_that("derive_vars_dt Test 38: NA imputation for highest_imputation = Y & ma
flag_imputation = "auto",
max_dates = exprs(TRTSDT)
)),
"If `highest_impuation` = \"Y\" and `max_dates` is specified, `date_imputation` should be set to \"last\"." # nolint
"If `highest_impuation` = \"Y\" and `date_imputation` = \"first\" is specified, `min_dates` should be specified." # nolint
)
})

Expand Down Expand Up @@ -839,7 +839,7 @@ test_that("derive_vars_dt Test 40: NA imputation for highest_imputation = Y & mi
flag_imputation = "auto",
min_dates = exprs(TRTSDT)
)),
"If `highest_impuation` = \"Y\" and `min_dates` is specified, `date_imputation` should be set to \"first\"." # nolint
"If `highest_impuation` = \"Y\" and `date_imputation` = \"last\" is specified, `max_dates` should be specified." # nolint
)
})

Expand All @@ -862,6 +862,33 @@ test_that("derive_vars_dt Test 41: NA imputation for highest_imputation = Y but
)
})

## Test 42: Supplying both min/max dates for highest_imputation = Y works ----
test_that("derive_vars_dt Test 42: Supplying both min/max dates for highest_imputation = Y works", { # nolint
actual <- data.frame(
AESTDTC = c(NA_character_, NA_character_),
TRTSDT = c(ymd("2022-01-01"), NA),
TRTEDT = c(ymd("2022-01-31"), NA)
) %>%
mutate(AESTDTC = as.character(AESTDTC)) %>%
derive_vars_dt(
dtc = AESTDTC,
new_vars_prefix = "AST",
highest_imputation = "Y",
min_dates = exprs(TRTSDT),
max_dates = exprs(TRTEDT)
)

expected <- data.frame(
AESTDTC = c(NA_character_, NA_character_),
TRTSDT = c(ymd("2022-01-01"), NA),
TRTEDT = c(ymd("2022-01-31"), NA),
ASTDT = c(ymd("2022-01-01"), NA),
ASTDTF = c("Y", NA)
)

expect_dfs_equal(actual, expected, keys = c("ASTDT", "ASTDTF"))
})

# derive_vars_dtm ----

input <- tibble::tribble(
Expand All @@ -875,8 +902,8 @@ input <- tibble::tribble(
"2019---07"
)

## Test 42: default behavior ----
test_that("derive_vars_dtm Test 42: default behavior", {
## Test 43: default behavior ----
test_that("derive_vars_dtm Test 43: default behavior", {
expected_output <- tibble::tribble(
~XXSTDTC, ~ASTDTM, ~ASTTMF,
"2019-07-18T15:25:40", ymd_hms("2019-07-18T15:25:40"), NA_character_,
Expand All @@ -901,8 +928,8 @@ test_that("derive_vars_dtm Test 42: default behavior", {
)
})

## Test 43: date imputed to first, auto DTF/TMF ----
test_that("derive_vars_dtm Test 43: date imputed to first, auto DTF/TMF", {
## Test 44: date imputed to first, auto DTF/TMF ----
test_that("derive_vars_dtm Test 44: date imputed to first, auto DTF/TMF", {
expected_output <- tibble::tribble(
~XXSTDTC, ~ASTDTM, ~ASTDTF, ~ASTTMF,
"2019-07-18T15:25:40", ymd_hms("2019-07-18T15:25:40"), NA_character_, NA_character_,
Expand All @@ -929,8 +956,8 @@ test_that("derive_vars_dtm Test 43: date imputed to first, auto DTF/TMF", {
)
})

## Test 44: date and time imputed to last, no DTF/TMF ----
test_that("derive_vars_dtm Test 44: date and time imputed to last, no DTF/TMF", {
## Test 45: date and time imputed to last, no DTF/TMF ----
test_that("derive_vars_dtm Test 45: date and time imputed to last, no DTF/TMF", {
expected_output <- tibble::tribble(
~XXSTDTC, ~AENDTM,
"2019-07-18T15:25:40", ymd_hms("2019-07-18T15:25:40"),
Expand Down Expand Up @@ -959,8 +986,8 @@ test_that("derive_vars_dtm Test 44: date and time imputed to last, no DTF/TMF",
)
})

## Test 45: date and time imputed to last, DTF only ----
test_that("derive_vars_dtm Test 45: date and time imputed to last, DTF only", {
## Test 46: date and time imputed to last, DTF only ----
test_that("derive_vars_dtm Test 46: date and time imputed to last, DTF only", {
expected_output <- tibble::tribble(
~XXSTDTC, ~AENDTM, ~AENDTF,
"2019-07-18T15:25:40", ymd_hms("2019-07-18T15:25:40"), NA_character_,
Expand Down Expand Up @@ -989,8 +1016,8 @@ test_that("derive_vars_dtm Test 45: date and time imputed to last, DTF only", {
)
})

## Test 46: date imputed to MID, time to first, TMF only ----
test_that("derive_vars_dtm Test 46: date imputed to MID, time to first, TMF only", {
## Test 47: date imputed to MID, time to first, TMF only ----
test_that("derive_vars_dtm Test 47: date imputed to MID, time to first, TMF only", {
expected_output <- tibble::tribble(
~XXSTDTC, ~ASTDTM, ~ASTTMF,
"2019-07-18T15:25:40", ymd_hms("2019-07-18T15:25:40"), NA_character_,
Expand Down Expand Up @@ -1019,8 +1046,8 @@ test_that("derive_vars_dtm Test 46: date imputed to MID, time to first, TMF only
)
})

## Test 47: No re-derivation is done if --DTF variable already exists ----
test_that("derive_vars_dtm Test 47: No re-derivation is done if --DTF variable already exists", {
## Test 48: No re-derivation is done if --DTF variable already exists ----
test_that("derive_vars_dtm Test 48: No re-derivation is done if --DTF variable already exists", {
expected_output <- tibble::tribble(
~XXSTDTC, ~ASTDTM, ~ASTDTF, ~ASTTMF,
"2019-07-18T15:25:40", ymd_hms("2019-07-18T15:25:40"), NA_character_, NA_character_,
Expand Down Expand Up @@ -1051,8 +1078,8 @@ test_that("derive_vars_dtm Test 47: No re-derivation is done if --DTF variable a
)
})

## Test 48: max_dates parameter works as expected ----
test_that("derive_vars_dtm Test 48: max_dates parameter works as expected", {
## Test 49: max_dates parameter works as expected ----
test_that("derive_vars_dtm Test 49: max_dates parameter works as expected", {
expected_output <- tibble::tribble(
~XXSTDTC, ~ASTDTM, ~ASTDTF, ~ASTTMF,
"2019-02", ymd_hms("2019-02-10T00:00:00"), "D", "H",
Expand Down Expand Up @@ -1088,8 +1115,8 @@ input_secs <- tibble::tribble(
"2019---07"
)

## Test 49: NA imputation for highest_imputation = Y & max_dates ----
test_that("derive_vars_dtm Test 49: NA imputation for highest_imputation = Y & max_dates", {
## Test 50: NA imputation for highest_imputation = Y & max_dates ----
test_that("derive_vars_dtm Test 50: NA imputation for highest_imputation = Y & max_dates", {
actual <- data.frame(
AESTDTC = c(NA_character_, NA_character_),
TRTSDTM = c(ymd_hms("2022-01-01 23:59:59"), NA)
Expand All @@ -1116,8 +1143,8 @@ test_that("derive_vars_dtm Test 49: NA imputation for highest_imputation = Y & m
expect_dfs_equal(actual, expected, keys = c("ASTDTM", "ASTDTF", "ASTTMF"))
})

## Test 50: NA imputation for highest_imputation = Y & max_dates but date_imputation = first ----
test_that("derive_vars_dtm Test 50: NA imputation for highest_imputation = Y & max_dates but date_imputation = first", { # nolint
## Test 51: NA imputation for highest_imputation = Y & max_dates but date_imputation = first ----
test_that("derive_vars_dtm Test 51: NA imputation for highest_imputation = Y & max_dates but date_imputation = first", { # nolint
expect_warning(
(data.frame(
AESTDTC = c(NA_character_, NA_character_),
Expand All @@ -1133,12 +1160,12 @@ test_that("derive_vars_dtm Test 50: NA imputation for highest_imputation = Y & m
flag_imputation = "both",
max_dates = exprs(TRTSDTM)
)),
"If `highest_impuation` = \"Y\" and `max_dates` is specified, `date_imputation` should be set to \"last\"." # nolint
"If `highest_impuation` = \"Y\" and `date_imputation` = \"first\" is specified, `min_dates` should be specified." # nolint
)
})

## Test 51: NA imputation for highest_imputation = Y & min_dates ----
test_that("derive_vars_dtm Test 51: NA imputation for highest_imputation = Y & min_dates", {
## Test 52: NA imputation for highest_imputation = Y & min_dates ----
test_that("derive_vars_dtm Test 52: NA imputation for highest_imputation = Y & min_dates", {
actual <- data.frame(
AESTDTC = c(NA_character_, NA_character_),
TRTSDTM = c(ymd_hms("2022-01-01 23:59:59"), NA)
Expand All @@ -1165,8 +1192,8 @@ test_that("derive_vars_dtm Test 51: NA imputation for highest_imputation = Y & m
expect_dfs_equal(actual, expected, keys = c("ASTDTM", "ASTDTF", "ASTTMF"))
})

## Test 52: NA imputation for highest_imputation = Y & min_dates but date_imputation = last ----
test_that("derive_vars_dtm Test 52: NA imputation for highest_imputation = Y & min_dates but date_imputation = last", { # nolint
## Test 53: NA imputation for highest_imputation = Y & min_dates but date_imputation = last ----
test_that("derive_vars_dtm Test 53: NA imputation for highest_imputation = Y & min_dates but date_imputation = last", { # nolint
expect_warning(
(data.frame(
AESTDTC = c(NA_character_, NA_character_),
Expand All @@ -1182,12 +1209,12 @@ test_that("derive_vars_dtm Test 52: NA imputation for highest_imputation = Y & m
flag_imputation = "both",
min_dates = exprs(TRTSDTM)
)),
"If `highest_impuation` = \"Y\" and `min_dates` is specified, `date_imputation` should be set to \"first\"." # nolint
"If `highest_impuation` = \"Y\" and `date_imputation` = \"last\" is specified, `max_dates` should be specified." # nolint
)
})

## Test 53: NA imputation for highest_imputation = Y but null min/max dates fails ----
test_that("derive_vars_dtm Test 53: NA imputation for highest_imputation = Y but null min/max dates fails", { # nolint
## Test 54: NA imputation for highest_imputation = Y but null min/max dates fails ----
test_that("derive_vars_dtm Test 54: NA imputation for highest_imputation = Y but null min/max dates fails", { # nolint
expect_error(
(data.frame(
AESTDTC = c(NA_character_, NA_character_),
Expand All @@ -1205,3 +1232,32 @@ test_that("derive_vars_dtm Test 53: NA imputation for highest_imputation = Y but
"If `highest_impuation` = \"Y\" is specified, `min_dates` or `max_dates` should be specified respectively." # nolint
)
})

## Test 55: Supplying both min/max dates for highest_imputation = Y works ----
test_that("derive_vars_dtm Test 55: Supplying both min/max dates for highest_imputation = Y works", { # nolint
actual <- data.frame(
AESTDTC = c(NA_character_, NA_character_),
TRTSDTM = c(ymd_hms("2022-01-01 23:59:59"), NA),
TRTEDTM = c(ymd_hms("2022-01-31 23:59:59"), NA)
) %>%
mutate(AESTDTC = as.character(AESTDTC)) %>%
derive_vars_dtm(
dtc = AESTDTC,
new_vars_prefix = "AST",
highest_imputation = "Y",
time_imputation = "last",
min_dates = exprs(TRTSDTM),
max_dates = exprs(TRTEDTM)
)

expected <- data.frame(
AESTDTC = c(NA_character_, NA_character_),
TRTSDTM = c(ymd_hms("2022-01-01 23:59:59"), NA),
TRTEDTM = c(ymd_hms("2022-01-31 23:59:59"), NA),
ASTDTM = c(ymd_hms("2022-01-01 23:59:59"), NA),
ASTDTF = c("Y", NA),
ASTTMF = c("H", NA)
)

expect_dfs_equal(actual, expected, keys = c("ASTDTM", "ASTDTF", "ASTTMF"))
})

0 comments on commit 6dead5a

Please sign in to comment.