Skip to content

Commit

Permalink
roxygen stuff and vignettes
Browse files Browse the repository at this point in the history
  • Loading branch information
zdz2101 committed Nov 3, 2023
1 parent affe938 commit a15e58a
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 12 deletions.
10 changes: 10 additions & 0 deletions R/derive_param_exposure.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
#' `PARAMCD` is expected as well,
#' + Either `ASTDTM` and `AENDTM` or `ASTDT` and `AENDT` are also expected.
#'
#' @param dataset_add Additional dataset
#'
#' The variables specified for `by_vars` are expected.
#' Observations from the specified dataset are going to be used to calculate and added
#' as new records to the input dataset (`dataset`).
#'
#'
#' @param filter Filter condition
#'
#' The specified condition is applied to the input dataset before deriving the
Expand Down Expand Up @@ -95,6 +102,7 @@
#' # Cumulative dose
#' adex %>%
#' derive_param_exposure(
#' dataset_add = adex,
#' by_vars = exprs(USUBJID),
#' set_values_to = exprs(PARAMCD = "TDOSE", PARCAT1 = "OVERALL"),
#' input_code = "DOSE",
Expand All @@ -106,6 +114,7 @@
#' # average dose in w2-24
#' adex %>%
#' derive_param_exposure(
#' dataset_add = adex,
#' by_vars = exprs(USUBJID),
#' filter = VISIT %in% c("WEEK 2", "WEEK 24"),
#' set_values_to = exprs(PARAMCD = "AVDW224", PARCAT1 = "WEEK2-24"),
Expand All @@ -118,6 +127,7 @@
#' # Any dose adjustment?
#' adex %>%
#' derive_param_exposure(
#' dataset_add = adex,
#' by_vars = exprs(USUBJID),
#' set_values_to = exprs(PARAMCD = "TADJ", PARCAT1 = "OVERALL"),
#' input_code = "ADJ",
Expand Down
15 changes: 6 additions & 9 deletions R/derive_summary_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
#' # Summarize the average of the triplicate ECG interval values (AVAL)
#' derive_summary_records(
#' adeg,
#' dataset_add = adeg,
#' by_vars = exprs(USUBJID, PARAM, AVISIT),
#' set_values_to = exprs(
#' AVAL = mean(AVAL, na.rm = TRUE),
Expand All @@ -123,6 +124,7 @@
#' # Derive more than one summary variable
#' derive_summary_records(
#' adeg,
#' dataset_add = adeg,
#' by_vars = exprs(USUBJID, PARAM, AVISIT),
#' set_values_to = exprs(
#' AVAL = mean(AVAL),
Expand Down Expand Up @@ -156,6 +158,7 @@
#' # by group
#' derive_summary_records(
#' adeg,
#' dataset_add = adeg,
#' by_vars = exprs(USUBJID, PARAM, AVISIT),
#' filter = n() > 2,
#' set_values_to = exprs(
Expand All @@ -172,17 +175,11 @@ derive_summary_records <- function(dataset,
filter_add = NULL,
analysis_var,
summary_fun,
set_values_to = NULL,
set_values_to,
missing_values = NULL) {
assert_vars(by_vars)
assert_data_frame(
dataset,
required_vars = expr_c(by_vars)
)
assert_data_frame(
dataset_add,
required_vars = expr_c(by_vars),
)
assert_data_frame(dataset, required_vars = by_vars)
assert_data_frame(dataset_add, required_vars = by_vars)
assert_data_frame(
dataset_ref,
required_vars = by_vars,
Expand Down
9 changes: 9 additions & 0 deletions man/derive_param_exposure.Rd

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

7 changes: 5 additions & 2 deletions man/derive_summary_records.Rd

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

1 change: 1 addition & 0 deletions tests/testthat/test-compute_scale.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ test_that("compute_scale Test 5: compute_scale() works as expected within
expect_equal(
derive_summary_records(
input,
dataset_add = input,
by_vars = exprs(STUDYID, USUBJID, AVISIT, AVISITN),
filter_add = (PARAMCD %in% c("ITEM1", "ITEM2", "ITEM3")),
set_values_to = exprs(
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-derive_param_exposure.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,23 @@ test_that("derive_param_exposure Test 2: works with DT variables", {

actual_output <- input_no_dtm %>%
derive_param_exposure(
dataset_add = input_no_dtm,
by_vars = exprs(USUBJID),
input_code = "DOSE",
analysis_var = AVAL,
summary_fun = function(x) sum(x, na.rm = TRUE),
set_values_to = exprs(PARAMCD = "TDOSE", PARCAT1 = "OVERALL")
) %>%
derive_param_exposure(
dataset_add = input_no_dtm,
by_vars = exprs(USUBJID),
input_code = "DOSE",
analysis_var = AVAL,
summary_fun = function(x) mean(x, na.rm = TRUE),
set_values_to = exprs(PARAMCD = "AVDOSE", PARCAT1 = "OVERALL")
) %>%
derive_param_exposure(
dataset_add = input_no_dtm,
by_vars = exprs(USUBJID),
input_code = "ADJ",
analysis_var = AVALC,
Expand All @@ -162,6 +165,7 @@ test_that("derive_param_exposure Test 3: Errors", {
expect_error(
input <- input %>%
derive_param_exposure(
dataset_add = input,
by_vars = exprs(USUBJID),
input_code = "DOSE",
analysis_var = AVAL,
Expand All @@ -174,6 +178,7 @@ test_that("derive_param_exposure Test 3: Errors", {
expect_error(
input <- input %>%
derive_param_exposure(
dataset_add = input,
by_vars = exprs(USUBJID),
input_code = "DOSED",
analysis_var = AVAL,
Expand All @@ -191,6 +196,8 @@ test_that("derive_param_exposure Test 3: Errors", {
input <- input %>%
select(-starts_with("AST"), -starts_with("AEN")) %>%
derive_param_exposure(
dataset = .,
dataset_add = .,
by_vars = exprs(USUBJID),
input_code = "DOSE",
analysis_var = AVAL,
Expand Down
2 changes: 2 additions & 0 deletions vignettes/bds_exposure.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ For example, to calculate the total dose by subject and treatment,
```{r eval=TRUE, echo=TRUE}
adex <- derive_param_exposure(
adex,
dataset_add = adex,
by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars),
input_code = "DOSE",
analysis_var = AVAL,
Expand Down Expand Up @@ -428,6 +429,7 @@ adex <- adex %>%
summary_fun = function(x) if_else(sum(!is.na(x)) > 0, "Y", NA_character_)
)
),
dataset_add = adex,
by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars)
)
Expand Down
3 changes: 2 additions & 1 deletion vignettes/bds_finding.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -989,9 +989,10 @@ Set `DTYPE` to `AVERAGE`.
```{r eval=TRUE}
advs_ex2 <- derive_summary_records(
advs,
dataset_add = advs,
by_vars = exprs(STUDYID, USUBJID, PARAMCD, VISITNUM, ADT),
set_values_to = exprs(
AVAL = mean(AVAL),
AVAL = mean(AVAL, na.rm = TRUE),
DTYPE = "AVERAGE"
)
)
Expand Down
7 changes: 7 additions & 0 deletions vignettes/questionnaires.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ adgad7 <- adqs %>%
# Select records to keep in the GAD-7 ADaM
filter(PARCAT1 == "GAD-7 V2") %>%
derive_summary_records(
dataset = .,
dataset_add = .,
by_vars = exprs(STUDYID, USUBJID, AVISIT, ADT, ADY, TRTSDT, DTHCAUS),
# Select records contributing to total score
filter_add = str_detect(PARAMCD, "GAD020[1-7]"),
Expand Down Expand Up @@ -169,6 +171,8 @@ adgdssf <- adqs %>%
# Select records to keep in the GDS-SF ADaM
filter(PARCAT1 == "GDS SHORT FORM") %>%
derive_summary_records(
dataset = .,
dataset_add = .,
by_vars = exprs(STUDYID, USUBJID, AVISIT, ADT, ADY, TRTSDT, DTHCAUS),
# Select records contributing to total score
filter_add = str_detect(PARAMCD, "GDS02[01][0-9]"),
Expand Down Expand Up @@ -518,6 +522,7 @@ be derived by `derive_summary_records()`.
```{r}
adgdssf <- adgdssf %>%
derive_summary_records(
dataset_add = adgdssf,
filter_add = str_detect(PARAMCD, "GDS02[01][0-9]"),
by_vars = exprs(USUBJID, AVISIT),
set_values_to = exprs(
Expand Down Expand Up @@ -567,6 +572,8 @@ adgdssf <- adgdssf %>%
)
) %>%
derive_summary_records(
dataset = .,
dataset_add = .,
filter_add = str_detect(PARAMCD, "GDS02[01][0-9]"),
by_vars = exprs(USUBJID, AVISIT),
set_values_to = exprs(
Expand Down

0 comments on commit a15e58a

Please sign in to comment.