Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
removed metatools from imports but moved suggests
  • Loading branch information
arjoon-r committed Jul 31, 2024
1 parent c2f817c commit 3d4715a
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 159 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
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"
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 @@ -31,7 +31,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
25 changes: 3 additions & 22 deletions man/derive_vars_merged_vaccine.Rd

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

123 changes: 1 addition & 122 deletions tests/testthat/test-derive_vars_merged_vaccine.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
## Test 1: Merging EXTRT variable from EX to FACE

test_that("derive_vars_merged_vaccine Test 1: Merging EXTRT variable from EX to FACE", {
face <- tibble::tribble(
~USUBJID, ~FACAT, ~FASCAT, ~FATESTCD, ~FAOBJ, ~FATEST, ~FALOC, ~FALAT, ~FATPTREF,
Expand Down Expand Up @@ -43,8 +41,6 @@ test_that("derive_vars_merged_vaccine Test 1: Merging EXTRT variable from EX to
actual <- derive_vars_merged_vaccine(
dataset = face,
dataset_ex = ex,
dataset_supp = NULL,
dataset_suppex = NULL,
by_vars_sys = exprs(USUBJID, FATPTREF = EXTPTREF),
by_vars_adms = exprs(USUBJID, FATPTREF = EXTPTREF, FALOC = EXLOC, FALAT = EXLAT),
ex_vars = exprs(EXTRT, EXDOSE)
Expand All @@ -55,123 +51,8 @@ test_that("derive_vars_merged_vaccine Test 1: Merging EXTRT variable from EX to
))
})

## Test 2: Check if supp datasets merged properly if they exist

test_that("derive_vars_merged_vaccine Test 2: Check if supp datasets merged
properly if they exist", {
face <- tibble::tribble(
~STUDYID, ~DOMAIN, ~USUBJID, ~FACAT, ~FASCAT, ~FATESTCD, ~FAOBJ, ~FATEST, ~FALOC, ~FALAT,
~FATPTREF, ~FASEQ,
"ABC", "FACE", "ABC101", "REACTO", "ADMINISTRATION SITE", "SEV", "Redness", "Severity", "ARM",
"RIGHT", "VAC 1", 1,
"ABC", "FACE", "ABC101", "REACTO", "ADMINISTRATION SITE", "DIAMETER", "Redness", "Diameter",
"ARM", "LEFT", "VAC 1", 2,
"ABC", "FACE", "ABC101", "REACTO", "ADMINISTRATION SITE", "DIAM", "Redness", "Diameter",
NA, NA, "VAC 2", 3,
"ABC", "FACE", "ABC101", "REACTO", "SYSTEMIC", "OCCUR", "Fatigue", "Occurrence",
"LEG", "LEFT", "VAC 3", 5,
"ABC", "FACE", "ABC101", "REACTO", "ADMINISTRATION SITE", "OCCUR", "Erythema",
"Occurrence", "LEG", "LEFT", "VAC 3", 6,
"ABC", "FACE", "ABC101", "REACTO", "ADMINISTRATION SITE", "SEV", "Swelling",
"Severity", NA, NA, "VAC 4", 7,
"ABC", "FACE", "ABC101", "REACTO", "ADMINISTRATION SITE", "OCCUR", "Swelling",
"Occurrence", NA, NA, "VAC 4", 8,
"ABC", "FACE", "ABC102", "REACTO", "ADMINISTRATION SITE", "OCCUR", "Swelling",
"Occurrence", NA, NA, "VAC 1", 1
)

ex <- tibble::tribble(
~STUDYID, ~DOMAIN, ~USUBJID, ~EXSTDTC, ~VISITNUM, ~EXTRT, ~EXTPTREF, ~VISIT, ~EXLOC, ~EXLAT,
~EXDOSE, ~EXSEQ,
"ABC", "EX", "ABC101", "2015-01-10", 1, "DRUG A", "VAC 1", "VISIT 1", "ARM", "RIGHT", 20, 1,
"ABC", "EX", "ABC101", "2015-01-11", 2, "DRUG A", "VAC 2", "VISIT 2", NA, NA, 30, 2,
"ABC", "EX", "ABC101", "2015-01-12", 3, "DRUG B", "VAC 3", "VISIT 3", "LEG", "LEFT", 25, 3,
"ABC", "EX", "ABC101", "2015-01-13", 4, "DRUG C", "VAC 4", "VISIT 4", NA, NA, 30, 4,
"ABC", "EX", "ABC102", "2015-01-13", 1, "DRUG B", "VAC 1", "VISIT 5", NA, NA, 10, 1
)

suppface <- tibble::tribble(
~STUDYID, ~USUBJID, ~RDOMAIN, ~IDVAR, ~IDVARVAL, ~QNAM, ~QVAL, ~QLABEL, ~QORIG,
"ABC", "ABC101", "FACE", "FASEQ", 1, "CLTYP", "DAIRY", "Collection Type",
"Predecessor",
"ABC", "ABC101", "FACE", "FASEQ", 2, "CLTYP", "CRF", "Collection Type",
"Predecessor"
)

suppex <- tibble::tribble(
~STUDYID, ~USUBJID, ~RDOMAIN, ~IDVAR, ~IDVARVAL, ~QNAM, ~QVAL, ~QLABEL, ~QORIG,
"ABC", "ABC101", "EX", "EXSEQ", 1, "EXTDV", "N", "Temporary Delay of Vaccination",
"ASSIGNED",
"ABC", "ABC101", "EX", "EXSEQ", 2, "EXTDV", "Y", "Temporary Delay of Vaccination",
"ASSIGNED"
)

temp <- suppface %>%
pivot_wider(
id_cols = c(USUBJID, IDVAR, IDVARVAL),
names_from = QNAM,
values_from = QVAL
) %>%
mutate(FASEQ = IDVARVAL) %>%
select(-c(IDVAR, IDVARVAL))
facef <- left_join(face, temp, by = c("USUBJID", "FASEQ"), keep = FALSE)
face1 <- facef %>%
mutate(LOC = FALOC, LAT = FALAT, TPTREF = FATPTREF)

tempex <- suppex %>%
pivot_wider(
id_cols = c(USUBJID, IDVAR, IDVARVAL),
names_from = QNAM,
values_from = QVAL
) %>%
mutate(EXSEQ = IDVARVAL) %>%
select(-c(IDVAR, IDVARVAL))
exf <- left_join(ex, tempex, by = c("USUBJID", "EXSEQ"), keep = FALSE)

ex1 <- exf %>%
mutate(LOC = EXLOC, LAT = EXLAT, TPTREF = EXTPTREF) %>%
select(-c(
"VISITNUM", "VISIT", "EXLOC", "EXLAT", "EXSTDTC",
"EXTPTREF", "STUDYID", "DOMAIN", "EXSEQ"
))

admin <- face1 %>%
filter(FASCAT == "ADMINISTRATION SITE")
expected1 <- left_join(admin,
ex1,
by = c("USUBJID", "LOC", "LAT", "TPTREF"), keep = FALSE
) %>%
select(-c("LOC", "LAT", "TPTREF"))

sys <- face1 %>% filter(FASCAT == "SYSTEMIC")
expected2 <- left_join(sys,
ex1,
by = c("USUBJID", "TPTREF"), keep = FALSE
) %>%
select(-c("TPTREF", "LOC.x", "LOC.y", "LAT.x", "LAT.y"))

expected <- bind_rows(expected1, expected2)


actual <- derive_vars_merged_vaccine(
dataset = face,
dataset_ex = ex,
dataset_supp = suppface,
dataset_suppex = suppex,
by_vars_sys = exprs(USUBJID, FATPTREF = EXTPTREF),
by_vars_adms = exprs(USUBJID, FATPTREF = EXTPTREF, FALOC = EXLOC, FALAT = EXLAT),
ex_vars = exprs(EXTRT, EXDOSE, EXTDV)
)
expect_dfs_equal(actual, expected, keys = c(
"USUBJID", "FAOBJ", "FATESTCD", "FATPTREF",
"FALOC", "FALAT"
))
})


## Test 3: Check if warning is raised when there are multiple vaccination in same visit

test_that("derive_vars_merged_vaccine Test 3: Check if warning is raised when
test_that("derive_vars_merged_vaccine Test 2: Check if warning is raised when
there are multiple vaccination in same ", {
face <- tibble::tribble(
~STUDYID, ~DOMAIN, ~USUBJID, ~FACAT, ~FASCAT, ~FATESTCD, ~FAOBJ, ~FATEST, ~FALOC, ~FALAT,
Expand Down Expand Up @@ -207,8 +88,6 @@ test_that("derive_vars_merged_vaccine Test 3: Check if warning is raised when
derive_vars_merged_vaccine(
dataset = face,
dataset_ex = ex,
dataset_supp = NULL,
dataset_suppex = NULL,
by_vars_sys = exprs(USUBJID, FATPTREF = EXTPTREF),
by_vars_adms = exprs(USUBJID, FATPTREF = EXTPTREF, FALOC = EXLOC, FALAT = EXLAT),
ex_vars = exprs(EXTRT, EXDOSE)
Expand Down
9 changes: 5 additions & 4 deletions vignettes/adface.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,15 @@ adsl <- convert_blanks_to_na(admiralvaccine_adsl)
## Pre-processing of Input Dataset {#input}

This step involves company-specific pre-processing of required input dataset for
further analysis. In this step, we will filter records that has only reactogenicity events.
further analysis. In this step, we will filter records that has only reactogenicity events and
combine the `face` and `ex` with their supplementary datasets `suppface` and `suppex` respectively.

```{r eval=TRUE}
face <- face %>%
filter(FACAT == "REACTOGENICITY" & grepl("ADMIN|SYS", FASCAT)) %>%
mutate(FAOBJ = str_to_upper(FAOBJ))
mutate(FAOBJ = str_to_upper(FAOBJ)) %>%
metatools::combine_supp(suppface)
ex <- metatools::combine_supp(ex, suppex)
```

```{r, echo=FALSE}
Expand All @@ -109,8 +112,6 @@ The function `derive_vars_merged_vaccine()` is used to merge `face` with `ex` do
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
2 changes: 1 addition & 1 deletion vignettes/adis.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ adsl <- convert_blanks_to_na(admiralvaccine_adsl)
## Combine IS with SUPPIS {#combine_supp}
Combine `IS` with its supplemental domain `SUPPIS`.
```{r eval=TRUE}
is_suppis <- combine_supp(is, suppis)
is_suppis <- metatools::combine_supp(is, suppis)
```


Expand Down

0 comments on commit 3d4715a

Please sign in to comment.