Skip to content

Commit

Permalink
#216 admiral_0_11_update: remove library() calls from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bundfussr committed Jun 1, 2023
1 parent 54dfe65 commit 5579e71
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 75 deletions.
13 changes: 4 additions & 9 deletions tests/testthat/test-check_crpr.R
@@ -1,9 +1,4 @@
library(tibble)
library(dplyr, warn.conflicts = FALSE)
library(lubridate)
library(admiraldev)

adrs <- tribble(
adrs <- tibble::tribble(
~USUBJID, ~ADTC, ~AVALC,
"1", "2020-01-01", "PR",
"1", "2020-02-01", "CR",
Expand All @@ -15,7 +10,7 @@ adrs <- tribble(
"2", "2020-03-30", "PR"
) %>%
mutate(
ADT = ymd(ADTC),
ADT = lubridate::ymd(ADTC),
STUDYID = "XX1234"
)

Expand Down Expand Up @@ -67,13 +62,13 @@ test_that("get_crpr_dataset() Test 2: dataset if returned", {
)

expect_dfs_equal(
base = tribble(
base = tibble::tribble(
~USUBJID, ~ADTC, ~AVALC,
"2", "2020-02-16", "CR",
"2", "2020-03-30", "PR"
) %>%
mutate(
ADT = ymd(ADTC),
ADT = lubridate::ymd(ADTC),
STUDYID = "XX1234"
),
compare = get_crpr_dataset(),
Expand Down
28 changes: 14 additions & 14 deletions tests/testthat/test-derive_param_bor.R
Expand Up @@ -29,7 +29,7 @@ adsl <- tibble::tribble(
"8", "2020-04-01", "008", "999"
) %>%
mutate(
TRTSDT = ymd(TRTSDTC),
TRTSDT = lubridate::ymd(TRTSDTC),
STUDYID = "XX1234"
)

Expand Down Expand Up @@ -92,7 +92,7 @@ aval_fun_pass <- function(arg) {
# excepcted dataframe, deviations from this are handeled in each individual test
expected_01 <- bind_rows(
adrs,
tribble(
tibble::tribble(
~USUBJID, ~ADTC, ~AVALC, ~AVAL, ~TRTSDTC, ~CHECKKEPTCOL,
"1", "2020-02-01", "CR", 11, "2020-01-01", "001",
"2", "2020-03-13", "CR", 11, "2019-12-12", "002",
Expand All @@ -104,8 +104,8 @@ expected_01 <- bind_rows(
"8", "", "MISSING", 77, "2020-04-01", "008"
) %>%
mutate(
ADT = ymd(ADTC),
TRTSDT = ymd(TRTSDTC),
ADT = lubridate::ymd(ADTC),
TRTSDT = lubridate::ymd(TRTSDTC),
STUDYID = "XX1234",
PARAMCD = "BOR",
PARAM = "Best Overall Response"
Expand Down Expand Up @@ -178,9 +178,9 @@ test_that("derive_param_bor Test 1: No source_pd", {
# set subject 7 to only have records before ADT
adrs_01 <- adrs
adrs_01$ADT[adrs_01$USUBJID == "7"][1:3] <- c(
ymd("2020-01-01"),
ymd("2020-01-02"),
ymd("2020-01-03")
lubridate::ymd("2020-01-01"),
lubridate::ymd("2020-01-02"),
lubridate::ymd("2020-01-03")
)

actual_02 <- derive_param_bor(
Expand All @@ -201,10 +201,10 @@ test_that("derive_param_bor Test 1: No source_pd", {
# expected will be the same as previous test except ADT for subject 7
expected_02 <- expected_01
expected_02$ADT[expected_02$USUBJID == "7"][1:4] <- c(
ymd("2020-01-01"),
ymd("2020-01-02"),
ymd("2020-01-03"),
ymd("2020-01-02")
lubridate::ymd("2020-01-01"),
lubridate::ymd("2020-01-02"),
lubridate::ymd("2020-01-03"),
lubridate::ymd("2020-01-02")
)

expect_dfs_equal(
Expand Down Expand Up @@ -240,7 +240,7 @@ test_that("derive_param_bor Test 1: No source_pd", {
# Expected Updated for Subject 7, response is now NE and 6 with a earlier ADT (first)
expected_03 <- expected_02
expected_03$AVALC[expected_03$USUBJID == "7"] <- "SD"
expected_03$ADT[expected_02$USUBJID == "7"][4] <- c(ymd("2020-01-01"))
expected_03$ADT[expected_02$USUBJID == "7"][4] <- c(lubridate::ymd("2020-01-01"))
expected_03$AVALC[expected_02$USUBJID == "7"][4] <- "NE"
expected_03$AVAL[expected_02$USUBJID == "7"][4] <- 66

Expand Down Expand Up @@ -305,7 +305,7 @@ test_that("derive_param_bor Test 2: With source_pd", {
expected_pd_01$AVAL[expected_pd_01$USUBJID == 2 &
expected_pd_01$PARAMCD == "BOR"] <- 22
expected_pd_01$ADT[expected_pd_01$USUBJID == 2 &
expected_pd_01$PARAMCD == "BOR"] <- ymd("2020-02-01")
expected_pd_01$PARAMCD == "BOR"] <- lubridate::ymd("2020-02-01")


# This is now MISSING as PD removed all records
Expand Down Expand Up @@ -396,7 +396,7 @@ test_that("derive_param_bor Test 4: Deprecation warning for aval_fun", {
expected_pd_01$AVAL[expected_pd_01$USUBJID == 2 &
expected_pd_01$PARAMCD == "BOR"] <- 22
expected_pd_01$ADT[expected_pd_01$USUBJID == 2 &
expected_pd_01$PARAMCD == "BOR"] <- ymd("2020-02-01")
expected_pd_01$PARAMCD == "BOR"] <- lubridate::ymd("2020-02-01")


# This is now MISSING as PD removed all records
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test-derive_param_clinbenefit.R
Expand Up @@ -10,8 +10,8 @@ adsl <- tibble::tribble(
) %>%
mutate(
STUDYID = "AB42",
TRTSDT = as_date(TRTSDT),
EOSDT = as_date(EOSDT),
TRTSDT = lubridate::as_date(TRTSDT),
EOSDT = lubridate::as_date(EOSDT),
)

adrs <- tibble::tribble(
Expand Down Expand Up @@ -44,7 +44,7 @@ adrs <- tibble::tribble(
) %>%
mutate(
STUDYID = "AB42",
ADT = as_date(ADT),
ADT = lubridate::as_date(ADT),
ANL01FL = "Y"
) %>%
derive_vars_merged(
Expand Down Expand Up @@ -79,7 +79,7 @@ test_that("derive_param_clinbenefit Test 1: ignore NON-CR/NON-PD", {
) %>%
mutate(
STUDYID = "AB42",
ADT = as_date(ADT),
ADT = lubridate::as_date(ADT),
ANL01FL = "Y"
) %>%
left_join(adsl, by = c("STUDYID", "USUBJID")) %>%
Expand Down Expand Up @@ -111,7 +111,7 @@ test_that("derive_param_clinbenefit Test 1: ignore NON-CR/NON-PD", {

## Test 2: No source_pd ----
test_that("derive_param_clinbenefit Test 2: No source_pd", {
input_cbr <- tribble(
input_cbr <- tibble::tribble(
~USUBJID, ~PARAMCD, ~AVALC, ~AVAL, ~ADT,
"01", "CBR", "Y", 1, "2021-03-07",
"02", "CBR", "Y", 1, "2021-03-07",
Expand All @@ -123,7 +123,7 @@ test_that("derive_param_clinbenefit Test 2: No source_pd", {
) %>%
mutate(
STUDYID = "AB42",
ADT = as_date(ADT),
ADT = lubridate::as_date(ADT),
ANL01FL = "Y"
) %>%
left_join(adsl, by = c("STUDYID", "USUBJID")) %>%
Expand Down Expand Up @@ -155,7 +155,7 @@ test_that("derive_param_clinbenefit Test 2: No source_pd", {

## Test 3: Deprecation warning for aval_fun ----
test_that("derive_param_clinbenefit Test 3: Deprecation warning for aval_fun", {
input_cbr <- tribble(
input_cbr <- tibble::tribble(
~USUBJID, ~PARAMCD, ~AVALC, ~AVAL, ~ADT,
"01", "CBR", "Y", 1, "2021-03-07",
"02", "CBR", "Y", 1, "2021-03-07",
Expand All @@ -167,7 +167,7 @@ test_that("derive_param_clinbenefit Test 3: Deprecation warning for aval_fun", {
) %>%
mutate(
STUDYID = "AB42",
ADT = as_date(ADT),
ADT = lubridate::as_date(ADT),
ANL01FL = "Y"
) %>%
left_join(adsl, by = c("STUDYID", "USUBJID")) %>%
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-derive_param_confirmed_bor.R
Expand Up @@ -48,7 +48,7 @@ adrs <- tibble::tribble(
"9", "2020-03-06", "SD"
) %>%
mutate(PARAMCD = "OVR") %>%
bind_rows(tribble(
bind_rows(tibble::tribble(
~USUBJID, ~ADTC, ~AVALC,
"9", "2020-02-16", "Y"
) %>%
Expand Down Expand Up @@ -94,7 +94,7 @@ test_that("derive_param_confirmed_bor Test 1: default confirmed BOR", {

expected <- bind_rows(
adrs,
tribble(
tibble::tribble(
~USUBJID, ~ADTC, ~AVALC, ~AVAL,
"1", "2020-02-01", "CR", 1,
"2", "2020-02-01", "SD", 3,
Expand Down Expand Up @@ -280,7 +280,7 @@ test_that("derive_param_confirmed_bor Test 4: No source_pd", {
"9", "2020-03-06", "SD", 3 # expected is now SD
) %>%
mutate(
ADT = ymd(ADTC),
ADT = lubridate::ymd(ADTC),
STUDYID = "XX1234",
PARAMCD = "CBOR",
PARAM = "Best Confirmed Overall Response by Investigator"
Expand Down Expand Up @@ -339,7 +339,7 @@ test_that("derive_param_confirmed_bor Test 5: Deprecation warning for aval_fun",
"9", "2020-03-06", "SD", 3 # expected is now SD
) %>%
mutate(
ADT = ymd(ADTC),
ADT = lubridate::ymd(ADTC),
STUDYID = "XX1234",
PARAMCD = "CBOR",
PARAM = "Best Confirmed Overall Response by Investigator"
Expand Down
11 changes: 6 additions & 5 deletions tests/testthat/test-derive_param_confirmed_resp.R
Expand Up @@ -251,7 +251,7 @@ test_that("derive_param_confirmed_resp Test 4: No source_pd", {

expected_no_source_pd <- bind_rows(
adrs,
tribble(
tibble::tribble(
~USUBJID, ~ADTC, ~AVALC, ~AVAL,
"1", "2020-02-16", "Y", 1,
"2", NA_character_, "N", 0,
Expand All @@ -264,7 +264,7 @@ test_that("derive_param_confirmed_resp Test 4: No source_pd", {
"9", NA_character_, "N", 0
) %>%
mutate(
ADT = ymd(ADTC),
ADT = lubridate::ymd(ADTC),
STUDYID = "XX1234",
PARAMCD = "CRSP",
PARAM = "Confirmed Response by Investigator"
Expand All @@ -278,7 +278,8 @@ test_that("derive_param_confirmed_resp Test 4: No source_pd", {
)
})

test_that("derive_param_confirmed_resp Test 4: Deprecation warning for aval_fun", {
## Test 5: Deprecation warning for aval_fun ----
test_that("derive_param_confirmed_resp Test 5: Deprecation warning for aval_fun", {
adrs <- tibble::tribble(
~USUBJID, ~ADTC, ~AVALC,
"1", "2020-01-01", "SD",
Expand Down Expand Up @@ -316,7 +317,7 @@ test_that("derive_param_confirmed_resp Test 4: Deprecation warning for aval_fun"

expected_no_source_pd <- bind_rows(
adrs,
tribble(
tibble::tribble(
~USUBJID, ~ADTC, ~AVALC, ~AVAL,
"1", "2020-02-16", "Y", 1,
"2", NA_character_, "N", 0,
Expand All @@ -329,7 +330,7 @@ test_that("derive_param_confirmed_resp Test 4: Deprecation warning for aval_fun"
"9", NA_character_, "N", 0
) %>%
mutate(
ADT = ymd(ADTC),
ADT = lubridate::ymd(ADTC),
STUDYID = "XX1234",
PARAMCD = "CRSP",
PARAM = "Confirmed Response by Investigator"
Expand Down

0 comments on commit 5579e71

Please sign in to comment.