Skip to content

Commit

Permalink
options for strict tests; few enhancements (#295)
Browse files Browse the repository at this point in the history
- part of
insightsengineering/coredev-tasks#478
- please read this for more info about the implementation:
insightsengineering/coredev-tasks#478 (comment)
- removed unnecessary empty first line in examples as this is actually
being rendered
- removed `library(random.cdisc.data)` as it's redundant

Please review the changes carefully and let me know if there is
something you don't like.

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
pawelru and github-actions[bot] authored Mar 4, 2024
1 parent 5eebe4b commit fad0aae
Show file tree
Hide file tree
Showing 47 changed files with 138 additions and 128 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Suggests:
diffdf,
knitr (>= 1.42),
rmarkdown (>= 2.19),
testthat (>= 3.0.4)
testthat (>= 3.0.4),
withr (>= 2.0.0)
VignetteBuilder:
knitr
RdMacros:
Expand All @@ -40,7 +41,7 @@ Config/Needs/verdepcheck: mllg/checkmate, tidyverse/dplyr,
r-lib/lifecycle, tidyverse/lubridate, tidyverse/magrittr, r-lib/rlang,
tidyverse/stringr, tidyverse/tibble, tidyverse/tidyr,
yaml=vubiostat/r-yaml, gowerc/diffdf, yihui/knitr, rstudio/rmarkdown,
r-lib/testthat
r-lib/testthat, r-lib/withr
Config/Needs/website: insightsengineering/nesttemplate
Config/testthat/edition: 3
Encoding: UTF-8
Expand Down
30 changes: 11 additions & 19 deletions R/radab.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#' @details One record per study per subject per parameter per time point: "R1800000", "RESULT1", "R1800001", "RESULT2".
#'
#' @examples
#' library(random.cdisc.data)
#' adsl <- radsl(N = 10, seed = 1, study_duration = 2)
#' adpc <- radpc(adsl, seed = 2, duration = 9 * 7)
#'
Expand Down Expand Up @@ -245,34 +244,25 @@ radab <- function(adsl,
adab_subj <- adab %>%
dplyr::group_by(USUBJID) %>%
dplyr::mutate(
pos_bl = any(PARAM == "ADA interpreted per sample result" &
!is.na(ABLFL) & AVALC == "POSITIVE"),
pos_bl_nab = any(PARAM == "NAB interpreted per sample result" &
!is.na(ABLFL) & AVALC == "POSITIVE"),
any_pos_postbl = any(PARAM == "ADA interpreted per sample result" &
is.na(ABLFL) & AVALC == "POSITIVE"),
any_pos_postbl_nab = any(PARAM == "NAB interpreted per sample result" &
is.na(ABLFL) & AVALC == "POSITIVE"),
pos_last_postbl = any(PARAM == "ADA interpreted per sample result" &
NFRLT == max(NFRLT) & AVALC == "POSITIVE"),
pos_bl = any(PARAM == "ADA interpreted per sample result" & !is.na(ABLFL) & AVALC == "POSITIVE"),
pos_bl_nab = any(PARAM == "NAB interpreted per sample result" & !is.na(ABLFL) & AVALC == "POSITIVE"),
any_pos_postbl = any(PARAM == "ADA interpreted per sample result" & is.na(ABLFL) & AVALC == "POSITIVE"),
any_pos_postbl_nab = any(PARAM == "NAB interpreted per sample result" & is.na(ABLFL) & AVALC == "POSITIVE"),
pos_last_postbl = any(PARAM == "ADA interpreted per sample result" & NFRLT == max(NFRLT) & AVALC == "POSITIVE"),
ada_bl = AVAL[PARAM == "Antibody titer units" & !is.na(ABLFL)],
nab_bl = AVAL[PARAM == "Neutralizing Antibody titer units" & !is.na(ABLFL)]
)
pos_tots <- adab_subj %>%
dplyr::summarise(
n_pos = sum(PARAM == "ADA interpreted per sample result" & AVALC == "POSITIVE"),
inc_postbl = sum(PARAM == "ADA interpreted per sample result" &
is.na(ABLFL) & (AVAL - ada_bl) > 0.60),
inc_postbl_nab = sum(PARAM == "NAB interpreted per sample result" &
is.na(ABLFL) & (AVAL - nab_bl) > 0.60),
onset_ada = if (any(PARAM == "ADA interpreted per sample result" &
AVALC == "POSITIVE")) {
inc_postbl = sum(PARAM == "ADA interpreted per sample result" & is.na(ABLFL) & (AVAL - ada_bl) > 0.60),
inc_postbl_nab = sum(PARAM == "NAB interpreted per sample result" & is.na(ABLFL) & (AVAL - nab_bl) > 0.60),
onset_ada = if (any(PARAM == "ADA interpreted per sample result" & AVALC == "POSITIVE")) {
min(NFRLT[PARAM == "ADA interpreted per sample result" & AVALC == "POSITIVE"])
} else {
NA
},
last_ada = if (any(PARAM == "ADA interpreted per sample result" &
AVALC == "POSITIVE")) {
last_ada = if (any(PARAM == "ADA interpreted per sample result" & AVALC == "POSITIVE")) {
max(NFRLT[PARAM == "ADA interpreted per sample result" & AVALC == "POSITIVE"])
} else {
NA
Expand Down Expand Up @@ -304,6 +294,7 @@ radab <- function(adsl,
adab[!(adab$PARAM %in% visit_lvl_params), ] <- adab %>%
dplyr::filter(!(PARAM %in% visit_lvl_params)) %>%
dplyr::mutate(
# nolint start indentation_linter
AVALC = dplyr::case_when(
(PARAM == "ADA Status of a patient" & any_pos_postbl) ~ "POSITIVE",
(PARAM == "ADA Status of a patient" & !any_pos_postbl) ~ "NEGATIVE",
Expand Down Expand Up @@ -366,6 +357,7 @@ radab <- function(adsl,
!((!pos_bl_nab & any_pos_postbl_nab) | (pos_bl_nab & inc_postbl_nab > 0))) ~ 1,
TRUE ~ 0
),
# nolint end indentation_linter
PARCAT1 = dplyr::case_when(
PARAM %in% c(
"Neutralizing Antibody titer units", "NAB interpreted per sample result",
Expand Down
1 change: 0 additions & 1 deletion R/radae.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#' @export
#'
#' @examples
#' library(random.cdisc.data)
#' adsl <- radsl(N = 10, study_duration = 2, seed = 1)
#'
#' adae <- radae(adsl, seed = 2)
Expand Down
1 change: 0 additions & 1 deletion R/radaette.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#' @author Xiuting Mi
#'
#' @examples
#' library(random.cdisc.data)
#' adsl <- radsl(N = 10, seed = 1, study_duration = 2)
#'
#' adaette <- radaette(adsl, seed = 2)
Expand Down
1 change: 0 additions & 1 deletion R/radcm.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#' @export
#'
#' @examples
#' library(random.cdisc.data)
#' adsl <- radsl(N = 10, seed = 1, study_duration = 2)
#'
#' adcm <- radcm(adsl, seed = 2)
Expand Down
1 change: 0 additions & 1 deletion R/raddv.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#' @export
#'
#' @examples
#' library(random.cdisc.data)
#' adsl <- radsl(N = 10, seed = 1, study_duration = 2)
#'
#' addv <- raddv(adsl, seed = 2)
Expand Down
1 change: 0 additions & 1 deletion R/radeg.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#' @author tomlinsj, npaszty, Xuefeng Hou, dipietrc
#'
#' @examples
#' library(random.cdisc.data)
#' adsl <- radsl(N = 10, seed = 1, study_duration = 2)
#'
#' adeg <- radeg(adsl, visit_format = "WEEK", n_assessments = 7L, seed = 2)
Expand Down
1 change: 0 additions & 1 deletion R/radex.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#' @export
#'
#' @examples
#' library(random.cdisc.data)
#' adsl <- radsl(N = 10, study_duration = 2, seed = 1)
#'
#' adex <- radex(adsl, seed = 2)
Expand Down
1 change: 0 additions & 1 deletion R/radhy.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#' @author wojciakw
#'
#' @examples
#' library(random.cdisc.data)
#' adsl <- radsl(N = 10, seed = 1, study_duration = 2)
#'
#' adhy <- radhy(adsl, seed = 2)
Expand Down
1 change: 0 additions & 1 deletion R/radlb.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#' @author tomlinsj, npaszty, Xuefeng Hou
#'
#' @examples
#' library(random.cdisc.data)
#' adsl <- radsl(N = 10, seed = 1, study_duration = 2)
#'
#' adlb <- radlb(adsl, visit_format = "WEEK", n_assessments = 7L, seed = 2)
Expand Down
1 change: 0 additions & 1 deletion R/radmh.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#' @export
#'
#' @examples
#' library(random.cdisc.data)
#' adsl <- radsl(N = 10, study_duration = 2, seed = 1)
#'
#' admh <- radmh(adsl, seed = 2)
Expand Down
11 changes: 6 additions & 5 deletions R/radpc.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#' @export
#'
#' @examples
#' library(random.cdisc.data)
#' adsl <- radsl(N = 10, seed = 1, study_duration = 2)
#'
#' adpc <- radpc(adsl, seed = 2)
Expand Down Expand Up @@ -67,8 +66,7 @@ radpc <- function(adsl,
PCTPTNUM = if (day == 1) c(0, 0.5, 1, 1.5, 2, 3, 4, 8, 12) else 24 * (day - 1),
PARAM = factor(c("Plasma Drug X", "Urine Drug X", "Plasma Drug Y", "Urine Drug Y"))
)
adpc_day <- adpc_day[!(grepl("Urine", adpc_day$PARAM) &
adpc_day$PCTPTNUM %in% c(0.5, 1, 1.5, 2, 3)), ] %>%
adpc_day <- adpc_day[!(grepl("Urine", adpc_day$PARAM) & adpc_day$PCTPTNUM %in% c(0.5, 1, 1.5, 2, 3)), ] %>%
dplyr::arrange(USUBJID, PARAM) %>%
dplyr::mutate(
VISITDY = day,
Expand Down Expand Up @@ -97,8 +95,11 @@ radpc <- function(adsl,
)
) %>%
dplyr::mutate(
PCVOL = ifelse(ASMED == "URINE", round(abs(((PCTPTNUM - 1) %% 24) *
A0 * ka * exp(PCTPTNUM %% 1.8 / 10)), 2), NA),
PCVOL = ifelse(
ASMED == "URINE",
round(abs(((PCTPTNUM - 1) %% 24) * A0 * ka * exp(PCTPTNUM %% 1.8 / 10)), 2),
NA
),
# PK Equation
AVALC = ifelse(AVAL == 0, "BLQ", as.character(AVAL)),
AVALU = avalu,
Expand Down
7 changes: 4 additions & 3 deletions R/radpp.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#' @export
#'
#' @examples
#' library(random.cdisc.data)
#' adsl <- radsl(N = 10, seed = 1, study_duration = 2)
#'
#' adpp <- radpp(adsl, seed = 2)
Expand Down Expand Up @@ -138,8 +137,10 @@ radpp <- function(adsl,
dplyr::left_join(t1_t2, by = c("PARAMCD"), multiple = "all", relationship = "many-to-many")

adpp <- dplyr::inner_join(adpp, adsl, by = c("STUDYID", "USUBJID")) %>%
dplyr::filter(ACTARM != "B: Placebo", !(ACTARM == "A: Drug X" &
(PPCAT == "Plasma Drug Y" | PPCAT == "Metabolite Drug Y")))
dplyr::filter(
ACTARM != "B: Placebo",
!(ACTARM == "A: Drug X" & (PPCAT == "Plasma Drug Y" | PPCAT == "Metabolite Drug Y"))
)

# derive PKARMCD column for creating more cohorts
adpp <- adpp %>%
Expand Down
Loading

0 comments on commit fad0aae

Please sign in to comment.