---
title: LBL01
subtitle: Listing of Laboratory Test Results
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(dplyr)
library(rlistings)
adlb <- random.cdisc.data::cadlb
adlb_x <- adlb %>%
filter(!is.na(AVAL) & !is.na(LBSEQ) & !is.na(ADY) & ANRIND != "") %>%
mutate(
CPID = paste(SITEID, SUBJID, sep = "/"),
PARAM_U = paste0(PARAMCD, "\n(", AVALU, " / NCI CTCAE grade)"),
ANRIND = factor(
case_when(
ANRIND == "LOW" ~ "L",
ANRIND == "HIGH" ~ "H",
TRUE ~ as.character(ANRIND)
),
levels = c("", "H", "L", "NORMAL")
),
AVALC = as.character(format(round(AVAL, 2), nsmall = 2))
) %>%
mutate(AVAL_GR = ifelse(
!ANRIND %in% c("H", "L"),
AVALC,
paste(AVALC, paste0(ANRIND, sub("-", "", ATOXGR)), sep = " / ")
)) %>%
select(CPID, TRT01A, ADY, LBSEQ, PARAM_U, AVAL_GR) %>%
unique()
out <- adlb_x %>%
arrange(CPID, ADY, PARAM_U, LBSEQ) %>%
tidyr::pivot_wider(
id_cols = c(TRT01A, CPID, ADY),
names_from = PARAM_U,
values_from = AVAL_GR
) %>%
group_by(CPID) %>%
mutate(DLD = ADY - lag(ADY)) %>%
ungroup() %>%
select(CPID, TRT01A, ADY, DLD, unique(adlb_x$PARAM_U))
var_labels(out) <- names(out)
out <- out %>%
var_relabel(
TRT01A = "Treatment",
CPID = "Center/Patient ID",
ADY = "Study\nDay",
DLD = "Days Since\nLast Dose of\nStudy Drug"
)
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
:::: panel-tabset
## Standard Listing
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r lsting, test = list(lsting = "lsting")}
lsting <- as_listing(
out,
key_cols = c("TRT01A", "CPID"),
disp_cols = names(out),
main_title = "Listing of Laboratory Test Results",
main_footer = "NCI CTCAE grade is displayed as abnormal high (H) or low (L) followed by the grade."
)
head(lsting, 20)
```
```{r include = FALSE}
webr_code_labels <- c("lsting")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Data Setup
```{r setup}
#| code-fold: show
```
::::
{{< include ../../_utils/save_results.qmd >}}
{{< include ../../repro.qmd >}}