Skip to content

Commit

Permalink
Merge pull request #68 from pharmaverse/fix_path_render
Browse files Browse the repository at this point in the history
hide hook_purl() outputs
  • Loading branch information
pawelru authored Jun 20, 2024
2 parents 572d657 + 3e34de2 commit 483a3da
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 105 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
editor:
markdown:
editor:
markdown:
wrap: 72
---

Expand Down Expand Up @@ -49,7 +49,8 @@ New Quarto pages should include the code snippet at the top for the
scripts to be produced.

```{r setup script, include=FALSE, purl=FALSE}
knitr::knit_hooks$set(purl = knitr::hook_purl)
invisible_hook_purl <- function(before, options, ...) {knitr::hook_purl(before, options, ...); NULL}
knitr::knit_hooks$set(purl = invisible_hook_purl)
```

# Contributing
Expand Down
13 changes: 7 additions & 6 deletions adam/adpc.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ order: 2
---

```{r setup script, include=FALSE, purl=FALSE}
knitr::knit_hooks$set(purl = knitr::hook_purl)
invisible_hook_purl <- function(before, options, ...) {knitr::hook_purl(before, options, ...); NULL}
knitr::knit_hooks$set(purl = invisible_hook_purl)
```

The Non-compartmental analysis (NCA) ADaM uses the CDISC Implementation Guide (<https://www.cdisc.org/standards/foundational/adam/adamig-non-compartmental-analysis-input-data-v1-0>). This example presented uses underlying `EX` and `PC` domains where the `EX` and `PC` domains represent data as collected and the `ADPC` ADaM is output. For more details see the `{admiral}` [vignette](https://pharmaverse.github.io/admiral/articles/pk_adnca.html){target="_blank"}.
Expand All @@ -31,7 +32,7 @@ library(pharmaverseadam)

## Next Load Specifications for Metacore

We have saved our specifications in an Excel file and will load them into `{metacore}` with the `metacore::spec_to_metacore()` function.
We have saved our specifications in an Excel file and will load them into `{metacore}` with the `metacore::spec_to_metacore()` function.

```{r echo=TRUE}
#| label: Load Specs
Expand Down Expand Up @@ -257,7 +258,7 @@ adpc_next <- adpc_prev %>%

### Find Previous and Next Nominal Dose

Use the same method to find the previous and next nominal times.
Use the same method to find the previous and next nominal times.

```{r}
#| label: Previous Nominal Dose
Expand Down Expand Up @@ -293,7 +294,7 @@ adpc_nom_next <- adpc_nom_prev %>%

### Combine PC and EX Data

Combine `PC` and `EX` records and derive the additional relative time variables.
Combine `PC` and `EX` records and derive the additional relative time variables.

```{r}
#| label: Combine
Expand Down Expand Up @@ -452,7 +453,7 @@ adpc_aval <- adpc_nrrlt %>%

### Derive DTYPE Copy Records

The CDISC ADaM Implementation Guide for Non-compartmental Analysis uses duplicated records for analysis when a record needs to be used in more than one way. In this example the 24 hour post-dose record will also be used a the pre-dose record for the "Day 2" dose.
The CDISC ADaM Implementation Guide for Non-compartmental Analysis uses duplicated records for analysis when a record needs to be used in more than one way. In this example the 24 hour post-dose record will also be used a the pre-dose record for the "Day 2" dose.

```{r}
#| label: DTYPE
Expand Down Expand Up @@ -537,7 +538,7 @@ adpc_aseq <- adpc_chg %>%

### Derive Additional Baselines

Here we derive additional baseline values from `VS` for baseline height `HTBL` and weight `WTBL` and compute the body mass index (BMI) with `compute_bmi()`.
Here we derive additional baseline values from `VS` for baseline height `HTBL` and weight `WTBL` and compute the body mass index (BMI) with `compute_bmi()`.

```{r}
#| label: Baselines
Expand Down
11 changes: 6 additions & 5 deletions adam/adppk.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ order: 3
---

```{r setup script, include=FALSE, purl=FALSE}
knitr::knit_hooks$set(purl = knitr::hook_purl)
invisible_hook_purl <- function(before, options, ...) {knitr::hook_purl(before, options, ...); NULL}
knitr::knit_hooks$set(purl = invisible_hook_purl)
```

The Population PK Analysis Data (ADPPK) follows the CDISC Implementation Guide (<https://www.cdisc.org/standards/foundational/adam/basic-data-structure-adam-poppk-implementation-guide-v1-0>). Population PK models generally make use of nonlinear mixed effects models that require numeric variables. The data used in the models will include both dosing and concentration records, relative time variables, and numeric covariate variables. A `DV` or dependent variable is often expected. For more details see the `{admiral}` [vignette](https://pharmaverse.github.io/admiral/articles/pk_adnca.html){target="_blank"}.
Expand Down Expand Up @@ -32,7 +33,7 @@ library(pharmaverseadam)

## Next Load Specifications for Metacore

We have saved our specifications in an Excel file and will load them into `{metacore}` with the `metacore::spec_to_metacore()` function.
We have saved our specifications in an Excel file and will load them into `{metacore}` with the `metacore::spec_to_metacore()` function.

```{r echo=TRUE, message=FALSE}
#| label: Load Specs
Expand Down Expand Up @@ -265,7 +266,7 @@ adppk_nom_prev <- adppk_prev %>%

### Combine PC and EX Data

Here we combine `PC` and `EX` records. We will derive the relative time variables `AFRLT` (Actual Relative Time from First Dose), `APRLT` (Actual Relative Time from Previous Dose), and `NPRLT` (Nominal Relative Time from Previous Dose).
Here we combine `PC` and `EX` records. We will derive the relative time variables `AFRLT` (Actual Relative Time from First Dose), `APRLT` (Actual Relative Time from Previous Dose), and `NPRLT` (Nominal Relative Time from Previous Dose).

```{r}
#| label: Combine
Expand Down Expand Up @@ -448,7 +449,7 @@ covar <- adsl %>%

### Derive Additional Baselines

Next we add additional baselines from vital signs and laboratory data.
Next we add additional baselines from vital signs and laboratory data.

```{r}
#| label: Baselines
Expand Down Expand Up @@ -538,7 +539,7 @@ adppk <- adppk_prefinal %>%

## Apply Labels and Formats with xportr

Using {xportr} we check variable type, assign variable lenght, add variable labels, add variable formats, and save a transport file with `xportr::xportr_write()`.
Using {xportr} we check variable type, assign variable lenght, add variable labels, add variable formats, and save a transport file with `xportr::xportr_write()`.

```{r}
#| label: xportr
Expand Down
39 changes: 20 additions & 19 deletions adam/adsl.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ order: 1
---

```{r setup script, include=FALSE, purl=FALSE}
knitr::knit_hooks$set(purl = knitr::hook_purl)
invisible_hook_purl <- function(before, options, ...) {knitr::hook_purl(before, options, ...); NULL}
knitr::knit_hooks$set(purl = invisible_hook_purl)
```

## Introduction
Expand Down Expand Up @@ -35,17 +36,17 @@ library(tidyr)
library(lubridate)
library(stringr)
# Read in input SDTM data
# Read in input SDTM data
data("dm")
data("ex")
```

Next we need to load the specification file in the form of a `{metacore}` object.

```{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")
```

Expand All @@ -66,8 +67,8 @@ 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.

```{r demographcis}
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)
```
Expand All @@ -83,12 +84,12 @@ Because this controlled terminology is written in a fairly standard format we ca
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 %>%
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) %>%
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
mutate(ARM = if_else(ARM == "Screen Failure", NA_character_, ARM),
TRT01P = if_else(TRT01P == "Screen Failure", NA_character_, TRT01P)
Expand Down Expand Up @@ -132,14 +133,14 @@ 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
head(adsl_raw, n=10)
Expand Down Expand Up @@ -187,13 +188,13 @@ Now we have all the variables defined we can run some checks before applying the

```{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
```
Loading

0 comments on commit 483a3da

Please sign in to comment.