Skip to content

Commit

Permalink
chore: #1822 styler and lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
Zelos Zhu committed May 9, 2023
1 parent 2dd86f2 commit dd7a6ad
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 49 deletions.
34 changes: 19 additions & 15 deletions R/derive_param_extreme_record.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@
#' @examples
#' aevent_samp <- tibble::tribble(
#' ~USUBJID, ~AESEQ, ~AETERM, ~AESTDTC,
#' "1" , 1, "X", "2022-01-01",
#' "1" , 2, "Y", "2022-01-02",
#' "1" , 3, "Z", "2022-01-03",
#' "2" , 1, "A", "2021-01-01",
#' "2" , 2, "B", "2021-01-02",
#' "2" , 3, "C", "2021-01-03",
#' "3" , 1, "J", "2023-01-01",
#' "3" , 2, "K", "2023-01-02",
#' "3" , 3, "L", "2023-01-03"
#' "1", 1, "X", "2022-01-01",
#' "1", 2, "Y", "2022-01-02",
#' "1", 3, "Z", "2022-01-03",
#' "2", 1, "A", "2021-01-01",
#' "2", 2, "B", "2021-01-02",
#' "2", 3, "C", "2021-01-03",
#' "3", 1, "J", "2023-01-01",
#' "3", 2, "K", "2023-01-02",
#' "3", 3, "L", "2023-01-03"
#' )
#'
#' cm <- tibble::tribble(
Expand All @@ -115,15 +115,18 @@
#' filter = CMDECOD == "ACT",
#' new_vars = exprs(
#' ADT = convert_dtc_to_dt(CMSTDTC),
#' AVALC = CMDECOD)
#' AVALC = CMDECOD
#' )
#' ),
#' records_source(
#' dataset_name = "pr",
#' filter = PRDECOD == "ACS",
#' new_vars = exprs(
#' ADT = convert_dtc_to_dt(PRSTDTC),
#' AVALC = PRDECOD)
#' )),
#' AVALC = PRDECOD
#' )
#' )
#' ),
#' source_datasets = list(cm = cm, pr = pr),
#' by_vars = exprs(USUBJID),
#' order = exprs(ADT),
Expand Down Expand Up @@ -170,9 +173,10 @@ derive_param_extreme_record <- function(dataset,
# Bind the source datasets together and parse out the extreme value
param_data <- bind_rows(data_list) %>%
filter_extreme(.,
by_vars = by_vars,
order = order,
mode = mode) %>%
by_vars = by_vars,
order = order,
mode = mode
) %>%
mutate(!!!set_values_to)

# Bind the parameter rows back to original dataset
Expand Down
27 changes: 15 additions & 12 deletions man/derive_param_extreme_record.Rd

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

51 changes: 29 additions & 22 deletions tests/testthat/test-derive_param_extreme_record.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# derive_param_extreme_record ----
## Test 1: New observations with analysis date are derived correctly ----
test_that("derive_param_extreme_record Test 1: New observations with analysis date are derived correctly", {
## Test 1: Analysis date are derived correctly ----
test_that("derive_param_extreme_record Test 1: Analysis date are derived correctly", {
aevent <- tibble::tribble(
~STUDYID, ~USUBJID, ~LBSTDTC, ~PARAMCD, ~PARAM,
"1001", "1", "2023-01-01", "TST", "TEST",
Expand All @@ -20,13 +20,13 @@ test_that("derive_param_extreme_record Test 1: New observations with analysis da
"1001", "3", "ACS", "2022-12-25",
)
expected_output <- tibble::tribble(
~STUDYID, ~USUBJID, ~LBSTDTC, ~PARAMCD, ~PARAM, ~ADT, ~AVALC,
"1001", "1", "2023-01-01", "TST", "TEST", NA, NA,
"1001", "2", "2023-01-01", "TST", "TEST", NA, NA,
"1001", "3", "2023-01-01", "TST", "TEST", NA, NA,
"1001", "1", NA, "FIRSTACT", "First Anti-Cancer Therapy", lubridate::ymd("2020-12-25"), "ACT",
"1001", "2", NA, "FIRSTACT", "First Anti-Cancer Therapy", lubridate::ymd("2021-12-25"), "ACS",
"1001", "3", NA, "FIRSTACT", "First Anti-Cancer Therapy", lubridate::ymd("2022-12-25"), "ACS"
~STUDYID, ~USUBJID, ~LBSTDTC, ~PARAMCD, ~PARAM, ~ADT, ~AVALC, # nolint
"1001", "1", "2023-01-01", "TST", "TEST", NA, NA, # nolint
"1001", "2", "2023-01-01", "TST", "TEST", NA, NA, # nolint
"1001", "3", "2023-01-01", "TST", "TEST", NA, NA, # nolint
"1001", "1", NA, "FIRSTACT", "First Anti-Cancer Therapy", lubridate::ymd("2020-12-25"), "ACT", # nolint
"1001", "2", NA, "FIRSTACT", "First Anti-Cancer Therapy", lubridate::ymd("2021-12-25"), "ACS", # nolint
"1001", "3", NA, "FIRSTACT", "First Anti-Cancer Therapy", lubridate::ymd("2022-12-25"), "ACS" # nolint
)
actual_output <- derive_param_extreme_record(
dataset = aevent,
Expand All @@ -36,15 +36,18 @@ test_that("derive_param_extreme_record Test 1: New observations with analysis da
filter = CMDECOD == "ACT",
new_vars = exprs(
ADT = convert_dtc_to_dt(CMSTDTC),
AVALC = CMDECOD)
AVALC = CMDECOD
)
),
records_source(
dataset_name = "pr",
filter = PRDECOD == "ACS",
new_vars = exprs(
ADT = convert_dtc_to_dt(PRSTDTC),
AVALC = PRDECOD)
)),
AVALC = PRDECOD
)
)
),
source_datasets = list(cm = cm, pr = pr),
by_vars = exprs(STUDYID, USUBJID),
order = exprs(ADT),
Expand All @@ -55,7 +58,7 @@ test_that("derive_param_extreme_record Test 1: New observations with analysis da
)
)

expect_dfs_equal(expected_output, actual_output, keys = c("USUBJID", "PARAMCD", "PARAM", "ADT", "AVALC"))
expect_dfs_equal(expected_output, actual_output, keys = c("USUBJID", "PARAMCD", "PARAM", "ADT", "AVALC")) # nolint
})

## Test 2: Error order variable not inside source datasets ----
Expand Down Expand Up @@ -87,15 +90,18 @@ test_that("derive_param_extreme_record Test 2: Error order variable not inside s
filter = CMDECOD == "ACT",
new_vars = exprs(
ADT = convert_dtc_to_dt(CMSTDTC),
AVALC = CMDECOD)
AVALC = CMDECOD
)
),
records_source(
dataset_name = "pr",
filter = PRDECOD == "ACS",
new_vars = exprs(
ADT = convert_dtc_to_dt(PRSTDTC),
AVALC = PRDECOD)
)),
AVALC = PRDECOD
)
)
),
source_datasets = list(cm = cm, pr = pr),
by_vars = exprs(STUDYID, USUBJID),
order = exprs(ADT2),
Expand Down Expand Up @@ -127,12 +133,13 @@ test_that("derive_param_extreme_record Test 3: Sources is not in proper list for
derive_param_extreme_record(
dataset = aevent,
sources = records_source(
dataset_name = "pr",
filter = PRDECOD == "ACS",
new_vars = exprs(
ADT = convert_dtc_to_dt(PRSTDTC),
AVALC = PRDECOD)
),
dataset_name = "pr",
filter = PRDECOD == "ACS",
new_vars = exprs(
ADT = convert_dtc_to_dt(PRSTDTC),
AVALC = PRDECOD
)
),
source_datasets = list(pr = pr),
by_vars = exprs(STUDYID, USUBJID),
order = exprs(ADT),
Expand Down

0 comments on commit dd7a6ad

Please sign in to comment.