Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #76 fix adsl bugs #79

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 20 additions & 23 deletions adam/adsl.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,36 @@ library(tidyr)
library(lubridate)
library(stringr)

# Read in input SDTM data
# Read in input SDTM data
data("dm")
data("ex")

## ----r metacore, warning=FALSE, results='hold'--------------------------------
# Read in metacore object
# Read in metacore object
load(metacore_example("pilot_ADaM.rda"))
metacore <- metacore %>%
metacore <- metacore %>%
select_dataset("ADSL")

## ----r------------------------------------------------------------------------
metacore$ds_vars

## ----r, error=TRUE------------------------------------------------------------
build_from_derived(metacore, list(), predecessor_only = FALSE)

## ----r demographcis-----------------------------------------------------------
rossfarrugia marked this conversation as resolved.
Show resolved Hide resolved
adsl_preds <- build_from_derived(metacore,
ds_list = list("dm" = dm),
adsl_preds <- build_from_derived(metacore,
ds_list = list("dm" = dm),
predecessor_only = FALSE, keep = TRUE)
head(adsl_preds, n=10)

## ----r------------------------------------------------------------------------
get_control_term(metacore, variable = AGEGR1)

## ----r ct---------------------------------------------------------------------
adsl_ct <- adsl_preds %>%
create_cat_var(metacore, ref_var = AGE,
grp_var = AGEGR1, num_grp_var = AGEGR1N) %>%
create_var_from_codelist(metacore = metacore,
input_var = RACE,
out_var = RACEN) %>%
#Removing screen failures from ARM and TRT01P to match the define and FDA guidence
adsl_ct <- adsl_preds %>%
create_cat_var(metacore, ref_var = AGE,
grp_var = AGEGR1, num_grp_var = AGEGR1N) %>%
create_var_from_codelist(metacore = metacore,
input_var = RACE,
out_var = RACEN) %>%
# Removing screen failures from ARM and TRT01P to match the define and FDA guidance
mutate(ARM = if_else(ARM == "Screen Failure", NA_character_, ARM),
TRT01P = if_else(TRT01P == "Screen Failure", NA_character_, TRT01P)
)
Expand Down Expand Up @@ -81,15 +78,15 @@ adsl_raw <- adsl_ct %>%
mode = "last",
by_vars = exprs(STUDYID, USUBJID)
) %>%
derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) %>% #Convert Datetime variables to date
derive_var_trtdurd() %>%
derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) %>% # Convert Datetime variables to date
derive_var_trtdurd() %>%
derive_var_merged_exist_flag(
dataset_add = ex,
by_vars = exprs(STUDYID, USUBJID),
new_var = SAFFL,
condition = (EXDOSE > 0 | (EXDOSE == 0 & str_detect(EXTRT, "PLACEBO")))
) %>%
drop_unspec_vars(metacore) #This will drop any columns that aren't specified in the metacore object
) %>%
drop_unspec_vars(metacore) # This will drop any columns that aren't specified in the metacore object

head(adsl_raw, n=10)

Expand Down Expand Up @@ -130,13 +127,13 @@ adsl_raw <- adsl_raw %>%

## ----r checks, warning=FALSE, message=FALSE-----------------------------------

adsl_raw %>%
adsl_raw %>%
check_variables(metacore) %>% # Check all variables specified are present and no more
check_ct_data(metacore, na_acceptable = TRUE) %>% # Checks all variables with CT only contain values within the CT
order_cols(metacore) %>% # Orders the columns according to the spec
sort_by_key(metacore) %>% # Sorts the rows by the sort keys
sort_by_key(metacore) %>% # Sorts the rows by the sort keys
xportr_type(metacore, domain = "ADSL") %>% # Coerce variable type to match spec
xportr_length(metacore) %>% # Assigns SAS length from a variable level metadata
xportr_label(metacore) %>% # Assigns variable label from metacore specifications
xportr_length(metacore) %>% # Assigns SAS length from a variable level metadata
xportr_label(metacore) %>% # Assigns variable label from metacore specifications
xportr_df_label(metacore) # Assigns dataset label from metacore specifications

12 changes: 4 additions & 8 deletions adam/adsl.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ metacore$ds_vars

## Start Building Derivations

The first derivation step we are going to do is to pull through all the columns that come directly from the SDTM datasets. You might know which datasets you are going to pull from directly already, but if you don't you can call `metatools::build_from_derived()` with just an empty list and the error will tell you which datasets you need to supply.

```{r, error=TRUE}
build_from_derived(metacore, list(), predecessor_only = FALSE)
```
The first derivation step we are going to do is to pull through all the columns that come directly from the SDTM datasets.

In this case all the columns come from `DM` so that is the only dataset we will pass into `metatools::build_from_derived()`. The resulting dataset has all the columns combined and any columns that needed renaming between SDTM and ADaM are renamed.

Expand Down Expand Up @@ -90,7 +86,7 @@ adsl_ct <- adsl_preds %>%
create_var_from_codelist(metacore = metacore,
input_var = RACE,
out_var = RACEN) %>%
#Removing screen failures from ARM and TRT01P to match the define and FDA guidence
# Removing screen failures from ARM and TRT01P to match the define and FDA guidance
mutate(ARM = if_else(ARM == "Screen Failure", NA_character_, ARM),
TRT01P = if_else(TRT01P == "Screen Failure", NA_character_, TRT01P)
)
Expand Down Expand Up @@ -133,15 +129,15 @@ adsl_raw <- adsl_ct %>%
mode = "last",
by_vars = exprs(STUDYID, USUBJID)
) %>%
derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) %>% #Convert Datetime variables to date
derive_vars_dtm_to_dt(source_vars = exprs(TRTSDTM, TRTEDTM)) %>% # Convert Datetime variables to date
derive_var_trtdurd() %>%
derive_var_merged_exist_flag(
dataset_add = ex,
by_vars = exprs(STUDYID, USUBJID),
new_var = SAFFL,
condition = (EXDOSE > 0 | (EXDOSE == 0 & str_detect(EXTRT, "PLACEBO")))
) %>%
drop_unspec_vars(metacore) #This will drop any columns that aren't specified in the metacore object
drop_unspec_vars(metacore) # This will drop any columns that aren't specified in the metacore object

head(adsl_raw, n=10)
```
Expand Down
4 changes: 2 additions & 2 deletions adam/index.qmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
title: "ADAM"
---
title: "ADaM"
---