Skip to content

Commit

Permalink
#1968 compute_multiple_vars: style files
Browse files Browse the repository at this point in the history
  • Loading branch information
bundfussr committed Jul 28, 2023
1 parent ab55517 commit e8c533f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
9 changes: 5 additions & 4 deletions R/derive_param_computed.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@
#' "2", "TBILI2", "N", "2021-11-11", NA_character_,
#' "3", "ALK2", "N", "2021-04-03", NA_character_,
#' "3", "TBILI2", "N", "2021-04-04", NA_character_
#' ) %>%
#' mutate(ADTM = ymd(ADTM))
#' ) %>%
#' mutate(ADTM = ymd(ADTM))
#'
#' derive_param_computed(
#' dataset_add = adlb_tbilialk,
Expand Down Expand Up @@ -315,7 +315,7 @@ derive_param_computed <- function(dataset = NULL,
"derive_param_computed(analysis_value = )",
"derive_param_computed(set_values_to = )"
)
set_values_to = exprs(!!analysis_var := !!enexpr(analysis_value), !!!set_values_to)
set_values_to <- exprs(!!analysis_var := !!enexpr(analysis_value), !!!set_values_to)
}

parameters <- assert_parameters_argument(parameters)
Expand Down Expand Up @@ -367,7 +367,8 @@ derive_param_computed <- function(dataset = NULL,
!!!parse_exprs(map_chr(
analysis_vars_chr,
~ str_c("!is.na(", .x, ")")
)))
))
)
}
hori_data <- hori_data %>%
process_set_values_to(set_values_to) %>%
Expand Down
36 changes: 19 additions & 17 deletions tests/testthat/test-derive_param_computed.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ test_that("derive_param_computed Test 1: new observations are derived correctly"
)

new_obs <-
inner_join(input %>% filter(PARAMCD == "DIABP") %>% select(USUBJID, VISIT, AVAL),
inner_join(
input %>% filter(PARAMCD == "DIABP") %>% select(USUBJID, VISIT, AVAL),
input %>% filter(PARAMCD == "SYSBP") %>% select(USUBJID, VISIT, AVAL),
by = c("USUBJID", "VISIT"),
suffix = c(".DIABP", ".SYSBP")
Expand Down Expand Up @@ -388,19 +389,19 @@ test_that("derive_param_computed Test 9: compute multiple variables, keep_nas",
expect_dfs_equal(
base = expected,
compare = derive_param_computed(
dataset_add = adlb_tbilialk,
by_vars = exprs(USUBJID),
parameters = c("ALK2", "TBILI2"),
set_values_to = exprs(
AVALC = if_else(AVALC.TBILI2 == "Y" & AVALC.ALK2 == "Y", "Y", "N"),
ADTM = pmax(ADTM.TBILI2, ADTM.ALK2),
ADTF = if_else(ADTM == ADTM.TBILI2, ADTF.TBILI2, ADTF.ALK2),
PARAMCD = "TB2AK2",
PARAM = "TBILI > 2 times ULN and ALKPH <= 2 times ULN"
dataset_add = adlb_tbilialk,
by_vars = exprs(USUBJID),
parameters = c("ALK2", "TBILI2"),
set_values_to = exprs(
AVALC = if_else(AVALC.TBILI2 == "Y" & AVALC.ALK2 == "Y", "Y", "N"),
ADTM = pmax(ADTM.TBILI2, ADTM.ALK2),
ADTF = if_else(ADTM == ADTM.TBILI2, ADTF.TBILI2, ADTF.ALK2),
PARAMCD = "TB2AK2",
PARAM = "TBILI > 2 times ULN and ALKPH <= 2 times ULN"
),
keep_nas = TRUE
),
keep_nas = TRUE
),
keys = c("USUBJID")
keys = c("USUBJID")
)
})

Expand All @@ -419,10 +420,11 @@ test_that("derive_param_computed Test 10: deprecation warning if analysis_value
)

new_obs <-
inner_join(input %>% filter(PARAMCD == "DIABP") %>% select(USUBJID, VISIT, AVAL),
input %>% filter(PARAMCD == "SYSBP") %>% select(USUBJID, VISIT, AVAL),
by = c("USUBJID", "VISIT"),
suffix = c(".DIABP", ".SYSBP")
inner_join(
input %>% filter(PARAMCD == "DIABP") %>% select(USUBJID, VISIT, AVAL),
input %>% filter(PARAMCD == "SYSBP") %>% select(USUBJID, VISIT, AVAL),
by = c("USUBJID", "VISIT"),
suffix = c(".DIABP", ".SYSBP")
) %>%
mutate(
AVAL = (2 * AVAL.DIABP + AVAL.SYSBP) / 3,
Expand Down

0 comments on commit e8c533f

Please sign in to comment.