---
title: LBT06
subtitle: Laboratory Abnormalities by Visit and Baseline Status
---
------------------------------------------------------------------------
{{< include ../../_utils/envir_hook.qmd >}}
```{r setup, echo = FALSE, warning = FALSE, message = FALSE}
library(tern)
library(dplyr)
adsl <- random.cdisc.data::cadsl
adlb <- random.cdisc.data::cadlb
# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
adsl <- df_explicit_na(adsl)
adlb <- df_explicit_na(adlb)
# Please note that df_explict_na has a na_level argument defaulting to "<Missing>",
# Please don't change the na_level to anything other than NA, empty string or the default "<Missing>".
adlb_f <- adlb %>%
dplyr::filter(ABLFL != "Y") %>%
dplyr::filter(!(AVISIT %in% c("SCREENING", "BASELINE"))) %>%
dplyr::mutate(AVISIT = droplevels(AVISIT)) %>%
var_relabel(AVISIT = "Visit")
adlb_f_crp <- adlb_f %>% dplyr::filter(PARAMCD == "CRP")
```
```{r include = FALSE}
webr_code_labels <- c("setup")
```
{{< include ../../_utils/webr_no_include.qmd >}}
## Output
::::: panel-tabset
## Standard Table for <br/> Single Lab Test
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant1, test = list(result_v1 = "result")}
# Define the split function
split_fun <- drop_split_levels
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ARM") %>%
split_rows_by("AVISIT", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(adlb_f_crp$AVISIT)) %>%
count_abnormal_by_baseline(
"ANRIND",
abnormal = c(Low = "LOW", High = "HIGH"),
.indent_mods = 4L
) %>%
append_varlabels(adlb_f_crp, "ANRIND", indent = 1L) %>%
append_topleft(" Baseline Status")
result <- build_table(
lyt = lyt,
df = adlb_f_crp,
alt_counts_df = adsl
) %>%
trim_rows()
result
```
```{r include = FALSE}
webr_code_labels <- c("variant1")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Standard Table for <br/> Multiple Lab Tests
::: {.panel-tabset .nav-justified group="webr"}
## {{< fa regular file-lines sm fw >}} Preview
```{r variant2, test = list(result_v2 = "result")}
# The following code generates one large table for multiple lab tests.
# If separate tables are needed for each lab test per GDSR standard, use the code for "single lab test".
lyt <- basic_table(show_colcounts = TRUE) %>%
split_cols_by("ARM") %>%
split_rows_by("PARAM", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(adlb_f$PARAM)) %>%
split_rows_by("AVISIT", split_fun = split_fun, label_pos = "topleft", split_label = obj_label(adlb_f$AVISIT)) %>%
count_abnormal_by_baseline(
"ANRIND",
abnormal = c(Low = "LOW", High = "HIGH"),
.indent_mods = 4L
) %>%
append_varlabels(adlb_f, "ANRIND", indent = 2L) %>%
append_topleft(" Baseline Status")
result <- build_table(
lyt = lyt,
df = adlb_f,
alt_counts_df = adsl
) %>%
trim_rows()
result
```
```{r include = FALSE}
webr_code_labels <- c("variant2")
```
{{< include ../../_utils/webr.qmd >}}
:::
## Data Setup
```{r setup}
#| code-fold: show
```
:::::
{{< include ../../_utils/save_results.qmd >}}
{{< include ../../repro.qmd >}}