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 #12 Add PK ADaM templates #15

Merged
merged 11 commits into from
Nov 17, 2023
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@ cache
_freeze
_site
site_libs
.DS_Store
.DS_Store
.Rproj.user
*.csv
*.xpt
*.rds
project.Rproj
.Rhistory
pharmaverse.examples.Rcheck/
pharmaverse.examples*.tar.gz
pharmaverse.examples*.tgz
2 changes: 1 addition & 1 deletion _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ format:
anchor-sections: true
smooth-scroll: true
code-link: true
code-fold: true
code-fold: false
code-overflow: scroll
code-line-numbers: true
code-copy: true
Expand Down
71 changes: 16 additions & 55 deletions adam/ADSL.qmd
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
---
title: "ADSL"
order: 1
---

## Introduction

This guide will show you how four pharmaverse packages, along with some from
tidyverse, can be used to create an ADaM such as `ADSL` end-to-end, using
`{pharmaversesdtm}` SDTM data as input.
This guide will show you how four pharmaverse packages, along with some from tidyverse, can be used to create an ADaM such as `ADSL` end-to-end, using `{pharmaversesdtm}` SDTM data as input.

The four packages used with a brief description of their purpose are as follows:

* [`{metacore}`](https://atorus-research.github.io/metacore/): provides harmonized
metadata/specifications object.
* [`{metatools}`](https://pharmaverse.github.io/metatools/): uses the provided
metadata to build/enhance and check the dataset.
* [`{admiral}`](https://pharmaverse.github.io/admiral/index.html): provides the
ADaM derivations.
* [`{xportr}`](https://atorus-research.github.io/xportr/): delivers the SAS
transport file (XPT) and eSub checks.
- [`{metacore}`](https://atorus-research.github.io/metacore/): provides harmonized metadata/specifications object.
- [`{metatools}`](https://pharmaverse.github.io/metatools/): uses the provided metadata to build/enhance and check the dataset.
- [`{admiral}`](https://pharmaverse.github.io/admiral/index.html): provides the ADaM derivations.
- [`{xportr}`](https://atorus-research.github.io/xportr/): delivers the SAS transport file (XPT) and eSub checks.

It is important to understand `{metacore}` objects by reading through the above
linked package site, as these are fundamental to being able to use `{metatools}`
and `{xportr}`. Each company may need to build a specification reader to create
these objects from their source standard specification templates.
It is important to understand `{metacore}` objects by reading through the above linked package site, as these are fundamental to being able to use `{metatools}` and `{xportr}`. Each company may need to build a specification reader to create these objects from their source standard specification templates.

## Load Data and Required pharmaverse Packages

Expand Down Expand Up @@ -53,29 +45,21 @@ metacore <- metacore %>%
select_dataset("ADSL")
```

Here is an example of how a `{metacore}` object looks showing variable level
metadata:
Here is an example of how a `{metacore}` object looks showing variable level metadata:

```{r}
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.
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)
```

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.
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.

```{r demographcis}
adsl_preds <- build_from_derived(metacore,
Expand All @@ -84,27 +68,15 @@ adsl_preds <- build_from_derived(metacore,
head(adsl_preds, n=10)
```

Now we have the base dataset, we can start to create some variables. We can start
with creating the subgroups using the controlled terminology, in this case `AGEGR1`.
The metacore object holds all the metadata needed to make `ADSL`. Part of that
metadata is the controlled terminology, which can help automate the creation of
subgroups. We can look into the `{metacore}` object and see the controlled
terminology for `AGEGR1`.
Now we have the base dataset, we can start to create some variables. We can start with creating the subgroups using the controlled terminology, in this case `AGEGR1`. The metacore object holds all the metadata needed to make `ADSL`. Part of that metadata is the controlled terminology, which can help automate the creation of subgroups. We can look into the `{metacore}` object and see the controlled terminology for `AGEGR1`.

```{r}
get_control_term(metacore, variable = AGEGR1)
```

Because this controlled terminology is written in a fairly standard format we
can automate the creation of `AGEGR1`. The function `metatools::create_cat_var()`
takes in a `{metacore}` object, a reference variable - in this case `AGE` because
that is the continuous variable `AGEGR1` is created from, and the name of the
sub-grouped variable. It will take the controlled terminology from the sub-grouped
variable and group the reference variables accordingly.
Because this controlled terminology is written in a fairly standard format we can automate the creation of `AGEGR1`. The function `metatools::create_cat_var()` takes in a `{metacore}` object, a reference variable - in this case `AGE` because that is the continuous variable `AGEGR1` is created from, and the name of the sub-grouped variable. It will take the controlled terminology from the sub-grouped variable and group the reference variables accordingly.

Using a similar philosophy we can create the numeric version of `RACE` using the
controlled terminology stored in the `{metacore}` object with the
`metatools::create_var_from_codelist()` function.
Using a similar philosophy we can create the numeric version of `RACE` using the controlled terminology stored in the `{metacore}` object with the `metatools::create_var_from_codelist()` function.

```{r ct}
adsl_ct <- adsl_preds %>%
Expand All @@ -121,13 +93,7 @@ adsl_ct <- adsl_preds %>%
head(adsl_ct, n=10)
```

Now we have sorted out what we can easily do with controlled terminology it is
time to start deriving some variables.
Here you could refer directly to using the `{admiral}` template and [vignette](https://pharmaverse.github.io/admiral/cran-release/articles/adsl.html)
in practice, but for the purpose of this end-to-end ADaM vignette we will share
a few exposure derivations from there.
We derive the start and end of treatment (which requires dates to first be
converted from DTC to DTM), the treatment duration, and the safety population flag.
Now we have sorted out what we can easily do with controlled terminology it is time to start deriving some variables. Here you could refer directly to using the `{admiral}` template and [vignette](https://pharmaverse.github.io/admiral/cran-release/articles/adsl.html) in practice, but for the purpose of this end-to-end ADaM vignette we will share a few exposure derivations from there. We derive the start and end of treatment (which requires dates to first be converted from DTC to DTM), the treatment duration, and the safety population flag.

```{r exposure}
ex_ext <- ex %>%
Expand Down Expand Up @@ -213,12 +179,7 @@ adsl_raw <- adsl_raw %>%

## Apply Metadata to Create an eSub XPT and Perform Associated Checks

Now we have all the variables defined we can run some checks before applying the
necessary formatting.
The top four functions performing checks and sorting/ordering come from
`{metatools}`, whereas the others focused around applying attributes to prepare
for XPT come from `{xportr}`. At the end you could add a call to
`xportr::xportr_write()` to produce the XPT file.
Now we have all the variables defined we can run some checks before applying the necessary formatting. The top four functions performing checks and sorting/ordering come from `{metatools}`, whereas the others focused around applying attributes to prepare for XPT come from `{xportr}`. At the end you could add a call to `xportr::xportr_write()` to produce the XPT file.

```{r checks, warning=FALSE, message=FALSE}

Expand Down
Loading