Skip to content

Commit

Permalink
Merge branch 'main' into 239-general-issue-remove-styler-dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasoplakus authored Jul 31, 2024
2 parents 2abaf3c + ab7dac5 commit df068a4
Show file tree
Hide file tree
Showing 16 changed files with 231 additions and 425 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ Imports:
lifecycle (>= 0.1.0),
lubridate (>= 1.7.4),
magrittr (>= 1.5),
metatools,
purrr (>= 0.3.3),
rlang (>= 0.4.4),
stringr (>= 1.4.0),
Expand All @@ -80,7 +79,8 @@ Suggests:
spelling,
testthat,
tibble,
usethis
usethis,
metatools
VignetteBuilder:
knitr
Encoding: UTF-8
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ importFrom(lubridate,years)
importFrom(lubridate,ymd)
importFrom(lubridate,ymd_hms)
importFrom(magrittr,"%>%")
importFrom(metatools,combine_supp)
importFrom(purrr,compose)
importFrom(purrr,every)
importFrom(purrr,flatten)
Expand Down
10 changes: 9 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# admiralvaccine (development version)
# admiralvaccine 0.3.0

## Breaking Changes

- Removed `dataset_supp` and `dataset_suppex` arguments from `derive_vars_merged_vaccine()` as we are not combining the parental with supplementary inside the function, but can be optionally combined in the ADCE, ADFACE and ADIS templates using `combine_supp()` function from {metatools}. (#246)

## Updates to Templates

- Supplementary domains are now optionally combined with parental domain within the template. (#246)

# admiralvaccine 0.2.0

Expand Down
1 change: 0 additions & 1 deletion R/admiralvaccine.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@
#' @importFrom admiraldev assert_logical_scalar assert_character_vector assert_vars
#' assert_data_frame assert_character_scalar assert_numeric_vector assert_filter_cond
#' assert_symbol assert_expr_list expect_dfs_equal
#' @importFrom metatools combine_supp
"_PACKAGE"
47 changes: 7 additions & 40 deletions R/derive_vars_merged_vaccine.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,15 @@
#' The variables to be added to the output dataset will be based on input variables
#' passed on `ex_vars` argument.
#'
#' @param dataset Input dataset
#' @param dataset Input dataset which should have been combined with the supplementary(if exists).
#'
#' The variables specified by the `by_vars` argument inside the
#' `derive_vars_merged`are expected.
#'
#' @param dataset_ex EX dataset to merge with the input dataset.
#' @param dataset_ex `ex` dataset(combined with `suppex`) to merge with the input dataset.
#'
#' The variables specified by the `ex_vars` argument are expected.
#'
#' @param dataset_supp Supplementary input dataset
#'
#' By default `dataset_supp` will be `NULL`, user has to provide
#' supplementary dataset to merge it back with original input dataset
#' if they have supplementary dataset in their case.
#'
#' @param dataset_suppex Supplementary EX dataset
#'
#' By default `dataset_suppex` will be `NULL`, user has to provide
#' supplementary dataset to merge it back with original `EX` dataset
#' if they have supplementary dataset in their case.
#'
#' @param by_vars_sys Grouping variables for systemic events.
#'
#' @param by_vars_adms Grouping variables for administration site events.
Expand All @@ -45,8 +33,7 @@
#' Only the variables passed to the `ex_vars` will be added in the output dataset
#'
#' If the input dataset has multiple vaccination for a subject at same visit
#' then this function will not merge ex dataset and will return only the input
#' dataset merged with its supplementary dataset.
#' then this function will not merge ex dataset and will return the `dataset`.
#'
#' @author Vikram S
#'
Expand All @@ -66,8 +53,6 @@
#' derive_vars_merged_vaccine(
#' dataset = face_vaccine,
#' dataset_ex = ex_vaccine,
#' dataset_supp = NULL,
#' dataset_suppex = NULL,
#' by_vars_sys = exprs(USUBJID, FATPTREF = EXLNKGRP),
#' by_vars_adms = exprs(USUBJID, FATPTREF = EXLNKGRP, FALOC = EXLOC, FALAT = EXLAT),
#' ex_vars = exprs(EXTRT, EXDOSE, EXDOSU, EXSTDTC, EXENDTC)
Expand All @@ -78,38 +63,21 @@
#' derive_vars_merged_vaccine(
#' dataset = face_vaccine,
#' dataset_ex = ex_vaccine,
#' dataset_supp = suppface_vaccine,
#' dataset_suppex = suppex_vaccine,
#' by_vars_sys = exprs(USUBJID, FATPTREF = EXLNKGRP),
#' by_vars_adms = exprs(USUBJID, FATPTREF = EXLNKGRP, FALOC = EXLOC, FALAT = EXLAT),
#' ex_vars = exprs(EXTRT, EXDOSE, EXDOSU, EXSTDTC, EXENDTC)
#' ) %>%
#' filter(CLTYP == "DAIRY") %>%
#' select(USUBJID, FATPTREF, CLTYP, EXTRT, EXDOSE, EXDOSU, EXSTDTC, EXENDTC)
#' )
#'
derive_vars_merged_vaccine <- function(dataset,
dataset_ex,
by_vars_sys,
by_vars_adms,
dataset_supp = NULL,
dataset_suppex = NULL,
ex_vars) {
assert_data_frame(dataset)
assert_vars(by_vars_sys)
assert_vars(by_vars_adms)
assert_vars(ex_vars)
assert_data_frame(dataset_supp, optional = TRUE)
assert_data_frame(dataset_ex)
assert_data_frame(dataset_suppex, optional = TRUE)

# combine face and suppface dataset
if (!is.null(dataset_supp)) {
dataset <- combine_supp(dataset, dataset_supp)
}

# combine face and suppex dataset
if (!is.null(dataset_suppex)) {
dataset_ex <- combine_supp(dataset_ex, dataset_suppex)
}

if ("VISIT" %in% names(dataset_ex)) {
ex_distinct <- dataset_ex %>% distinct(USUBJID, VISIT, .keep_all = TRUE)
Expand All @@ -119,8 +87,7 @@ derive_vars_merged_vaccine <- function(dataset,

if (nrow(dataset_ex) != nrow(ex_distinct)) {
warning("Subjects have multiple vaccinations at same visit")

dataset <- dataset
return(dataset)
} else {
# Filter records for ADMINISTRATION SITE events and merge it with EX dataset
dataset_adminstration <- dataset %>%
Expand All @@ -145,6 +112,6 @@ derive_vars_merged_vaccine <- function(dataset,
)

# bind face1 and face2 datasets
bind_rows(face1, face2)
return(bind_rows(face1, face2))
}
}
8 changes: 4 additions & 4 deletions inst/templates/ad_adce.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ adce02 <- adce01 %>%
derive_vars_merged(
dataset_add = adsl,
new_vars = adsl_vars,
by = exprs(STUDYID, USUBJID)
by = get_admiral_option("subject_keys")
) %>%
## Derive analysis start time
## Proposed imputations depending on situation: no needed -> highest imputation = “n”
Expand Down Expand Up @@ -84,7 +84,7 @@ adce03 <-
derive_vars_joined(
adce02,
dataset_add = adperiods,
by_vars = exprs(STUDYID, USUBJID),
by_vars = get_admiral_option("subject_keys"),
filter_join = ASTDT >= APERSDT & ASTDT <= APEREDT,
join_type = "all"
) %>%
Expand Down Expand Up @@ -121,7 +121,7 @@ adce05 <- adce04 %>%
## Derive ASEQ
derive_var_obs_number(
new_var = ASEQ,
by_vars = exprs(STUDYID, USUBJID),
by_vars = get_admiral_option("subject_keys"),
order = exprs(CEDECOD, CELAT, CETPTREF, APERIOD),
check_type = "error"
) %>%
Expand All @@ -146,7 +146,7 @@ adsl_list <- adsl %>%
adce <- adce05 %>%
derive_vars_merged(
dataset_add = adsl_list,
by_vars = exprs(STUDYID, USUBJID)
by_vars = get_admiral_option("subject_keys")
)


Expand Down
20 changes: 11 additions & 9 deletions inst/templates/ad_adface.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ face <- face %>%

adsl_vars <- exprs(RFSTDTC, RFENDTC)

# Combine the parental datasets with their respective supp datasets (only if exist)
# User can use `combine_supp()` from {metatools} to combine the parental with supp dataset.

face <- metatools::combine_supp(face, suppface)
ex <- metatools::combine_supp(ex, suppex)

# Step 2 - Merging supplementary datasets and FACE with EX

adface <- derive_vars_merged_vaccine(
dataset = face,
dataset_ex = ex,
dataset_supp = suppface,
dataset_suppex = suppex,
by_vars_sys = exprs(USUBJID, FATPTREF = EXLNKGRP),
by_vars_adms = exprs(USUBJID, FATPTREF = EXLNKGRP, FALOC = EXLOC, FALAT = EXLAT),
ex_vars = exprs(EXTRT, EXDOSE, EXSEQ, EXSTDTC, EXENDTC, VISIT, VISITNUM)
Expand All @@ -73,7 +77,7 @@ adface <- derive_vars_merged_vaccine(
derive_vars_merged(
dataset_add = adsl,
new_vars = adsl_vars,
by_vars = exprs(STUDYID, USUBJID)
by_vars = get_admiral_option("subject_keys")
) %>%
# Step 4 - Deriving Fever OCCUR records from VS if FAOBJ = "FEVER" records not present in FACE
derive_fever_records(
Expand Down Expand Up @@ -103,7 +107,7 @@ period_ref <- create_period_dataset(
adface <- derive_vars_joined(
adface,
dataset_add = period_ref,
by_vars = exprs(STUDYID, USUBJID),
by_vars = get_admiral_option("subject_keys"),
filter_join = ADT >= APERSDT & ADT <= APEREDT,
join_type = "all"
) %>%
Expand Down Expand Up @@ -208,7 +212,7 @@ lookup_dataset <- tribble(
"MAXDIAM", "MDISW", 29, "Maximum Diameter", "SWELLING",
"MAXSEV", "MAXSPIS", 30, "Maximum Severity", "PAIN AT INJECTION SITE",
"OCCUR", "OCCVOM", 31, "Occurrence Indicator", "VOMITING",
"DIAMETER", "DIASWEL", 32, "Diameter", "SWELLING",
"DIAMETER", "DIASWEL", 32, "Diameter", "SWELLING"
)

adface <- derive_vars_params(
Expand Down Expand Up @@ -237,7 +241,7 @@ adsl <- adsl %>%
adface <- derive_vars_merged(
dataset = adface,
dataset_add = select(adsl, !!!negate_vars(adsl_vars)),
by_vars = exprs(STUDYID, USUBJID)
by_vars = get_admiral_option("subject_keys")
) %>%
# Step 16 post processing
post_process_reacto(
Expand All @@ -261,13 +265,11 @@ keep_vars <- c(
"APEREDT", "APERETM", "APEREDTM", "APERDY", "FAORRES"
)

adface <- adface %>% select(
admiralvaccine_adface <- adface %>% select(
any_of(keep_vars), starts_with("TRT0"), starts_with("VAX"),
starts_with("EVE"), starts_with("ANL")
)

admiralvaccine_adface <- adface

# Save output ----

dir <- tools::R_user_dir("admiralvaccine_templates_data", which = "cache")
Expand Down
Loading

0 comments on commit df068a4

Please sign in to comment.