library(dplyr)
library(admiral)
# ensure that `date_source()` from admiralonco is used to avoid deprecation
# warning
unloadNamespace("admiralonco")
library(admiralonco)
library(lubridate)
library(tibble)
adsl <- tribble(
~USUBJID,
"1",
"2",
"3",
"4"
) %>%
mutate(STUDYID = "XX1234")
adrs <- tribble(
~USUBJID, ~PARAMCD, ~ADTC, ~AVALC, ~ANL01FL,
"1", "OVR", "2020-01-02", "PR", "Y",
"1", "OVR", "2020-02-01", "CR", "Y",
"1", "OVR", "2020-03-01", "CR", "Y",
"1", "OVR", "2020-04-01", "SD", "Y",
"1", "PD", NA_character_, "N", "Y",
"2", "OVR", "2021-06-15", "SD", "Y",
"2", "OVR", "2021-07-16", "PD", "Y",
"2", "OVR", "2021-09-14", "PD", "Y",
"2", "PD", "2021-09-14", "Y", "Y",
"3", "OVR", "2021-09-14", "SD", "Y",
"3", "OVR", "2021-10-30", "PD", "Y",
"3", "OVR", "2021-12-25", "CR", "Y",
"3", "PD", "2021-10-30", "Y", "Y"
) %>%
mutate(
STUDYID = "XX1234",
ADT = ymd(ADTC),
ANL01FL = "Y"
) %>%
select(-ADTC)
# Define the end of the assessment period for responses:
# all responses before or on the first PD will be used.
pd <- date_source(
dataset_name = "adrs",
date = ADT,
filter = PARAMCD == "PD" & AVALC == "Y"
)
# Derive the response parameter
derive_param_response(
dataset = adrs,
dataset_adsl = adsl,
filter_source = PARAMCD == "OVR" & AVALC %in% c("CR", "PR") & ANL01FL == "Y",
source_pd = pd,
source_datasets = list(adrs = adrs),
set_values_to = exprs(
AVAL = yn_to_numeric(AVALC),
PARAMCD = "RSP",
PARAM = "Response by investigator"
),
subject_keys = get_admiral_option("subject_keys")
) %>%
arrange(USUBJID, PARAMCD, ADT)
Run the code above in your browser using DataLab