Skip to content

Commit

Permalink
Merge branch 'main' into 240-Documentation-and-Templates
Browse files Browse the repository at this point in the history
  • Loading branch information
ahasoplakus authored Jul 31, 2024
2 parents 309c434 + 34fa7c0 commit 6efb1f8
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 203 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 @@ -81,7 +80,8 @@ Suggests:
styler,
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))
}
}
12 changes: 7 additions & 5 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 Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion inst/templates/ad_adis.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ adsl <- convert_blanks_to_na(admiralvaccine_adsl)

# STEP 1 - combine IS with SUPPIS.
# Please, upload MOCK data
is_suppis <- combine_supp(is, suppis)
is_suppis <- metatools::combine_supp(is, suppis)


# STEP 2 - Visits and timing variables derivation.
Expand Down
30 changes: 5 additions & 25 deletions man/derive_vars_merged_vaccine.Rd

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

Loading

0 comments on commit 6efb1f8

Please sign in to comment.