Skip to content

Commit

Permalink
#17 add reactable
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyad committed Sep 26, 2024
1 parent b9cc207 commit 7432194
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions adam/adpc.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ library(metatools)
library(xportr)
library(pharmaversesdtm)
library(pharmaverseadam)
library(reactable)

## ----r echo=TRUE--------------------------------------------------------------
# ---- Load Specs for Metacore ----
Expand Down Expand Up @@ -58,6 +59,8 @@ pc_dates <- pc %>%
NFRLT = if_else(PCTPTNUM < 0, 0, PCTPTNUM), .after = USUBJID
)

reactable(pc_dates)

## ----r------------------------------------------------------------------------
ex_dates <- ex %>%
derive_vars_merged(
Expand Down Expand Up @@ -98,6 +101,8 @@ ex_dates <- ex %>%
derive_vars_dtm_to_dt(exprs(ASTDTM)) %>%
derive_vars_dtm_to_dt(exprs(AENDTM))

reactable(ex_dates)

## ----r------------------------------------------------------------------------
ex_exp <- ex_dates %>%
create_single_dose_dataset(
Expand Down Expand Up @@ -132,6 +137,8 @@ ex_exp <- ex_dates %>%
derive_vars_dtm_to_tm(exprs(AENDTM)) %>%
derive_vars_dy(reference_date = TRTSDT, source_vars = exprs(ADT))

reactable(ex_exp)

## ----r------------------------------------------------------------------------
adpc_first_dose <- pc_dates %>%
derive_vars_merged(
Expand All @@ -151,6 +158,8 @@ adpc_first_dose <- pc_dates %>%
AVISIT = paste("Day", AVISITN),
)

reactable(adpc_first_dose)

## ----r------------------------------------------------------------------------
adpc_prev <- adpc_first_dose %>%
derive_vars_joined(
Expand Down Expand Up @@ -186,6 +195,8 @@ adpc_next <- adpc_prev %>%
check_type = "none"
)

reactable(adpc_prev)

## ----r------------------------------------------------------------------------
adpc_nom_prev <- adpc_next %>%
derive_vars_joined(
Expand Down Expand Up @@ -272,6 +283,8 @@ adpc_arrlt <- bind_rows(adpc_nom_next, ex_exp) %>%
derive_vars_dtm_to_dt(exprs(PCRFTDTM)) %>%
derive_vars_dtm_to_tm(exprs(PCRFTDTM))

reactable(adpc_arrlt)

## ----r------------------------------------------------------------------------
# Derive Nominal Relative Time from Reference Dose (NRRLT)

Expand Down Expand Up @@ -353,6 +366,8 @@ adpc_aval <- adpc_nrrlt %>%
SRCSEQ = coalesce(PCSEQ, EXSEQ)
)

reactable(adpc_aval)

## ----r------------------------------------------------------------------------
dtype <- adpc_aval %>%
filter(NFRLT > 0 & NXRLT == 0 & EVID == 0 & !is.na(AVISIT_next)) %>%
Expand All @@ -374,6 +389,8 @@ dtype <- adpc_aval %>%
derive_vars_dtm_to_dt(exprs(PCRFTDTM)) %>%
derive_vars_dtm_to_tm(exprs(PCRFTDTM))

reactable(dtype)

## ----r------------------------------------------------------------------------
adpc_dtype <- bind_rows(adpc_aval, dtype) %>%
arrange(STUDYID, USUBJID, BASETYPE, ADTM, NFRLT) %>%
Expand Down Expand Up @@ -452,6 +469,8 @@ adpc <- adpc_prefinal %>%
order_cols(metacore) %>% # Orders the columns according to the spec
sort_by_key(metacore) # Sorts the rows by the sort keys

reactable(adpc)

## ----r------------------------------------------------------------------------
dir <- tempdir() # Change to whichever directory you want to save the dataset in

Expand Down
19 changes: 19 additions & 0 deletions adam/adpc.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ library(metatools)
library(xportr)
library(pharmaversesdtm)
library(pharmaverseadam)
library(reactable)
```

## Next Load Specifications for Metacore
Expand Down Expand Up @@ -98,6 +99,8 @@ pc_dates <- pc %>%
DRUG = PCTEST,
NFRLT = if_else(PCTPTNUM < 0, 0, PCTPTNUM), .after = USUBJID
)
reactable(pc_dates)
```

### Get Dosing Information
Expand Down Expand Up @@ -145,6 +148,8 @@ ex_dates <- ex %>%
# Derive dates from date/times
derive_vars_dtm_to_dt(exprs(ASTDTM)) %>%
derive_vars_dtm_to_dt(exprs(AENDTM))
reactable(ex_dates)
```

### Expand Dosing Records
Expand Down Expand Up @@ -186,6 +191,8 @@ ex_exp <- ex_dates %>%
derive_vars_dtm_to_tm(exprs(ASTDTM)) %>%
derive_vars_dtm_to_tm(exprs(AENDTM)) %>%
derive_vars_dy(reference_date = TRTSDT, source_vars = exprs(ADT))
reactable(ex_exp)
```

### Find First Dose
Expand All @@ -212,6 +219,8 @@ adpc_first_dose <- pc_dates %>%
AVISITN = NFRLT %/% 24 + 1,
AVISIT = paste("Day", AVISITN),
)
reactable(adpc_first_dose)
```

### Find Previous Dose and Next Dose
Expand Down Expand Up @@ -254,6 +263,8 @@ adpc_next <- adpc_prev %>%
mode = "first",
check_type = "none"
)
reactable(adpc_prev)
```

### Find Previous and Next Nominal Dose
Expand Down Expand Up @@ -354,6 +365,8 @@ adpc_arrlt <- bind_rows(adpc_nom_next, ex_exp) %>%
derive_vars_dtm_to_tm(exprs(FANLDTM)) %>%
derive_vars_dtm_to_dt(exprs(PCRFTDTM)) %>%
derive_vars_dtm_to_tm(exprs(PCRFTDTM))
reactable(adpc_arrlt)
```

### Derive Nominal Reference
Expand Down Expand Up @@ -449,6 +462,8 @@ adpc_aval <- adpc_nrrlt %>%
SRCVAR = "SEQ",
SRCSEQ = coalesce(PCSEQ, EXSEQ)
)
reactable(adpc_aval)
```

### Derive DTYPE Copy Records
Expand Down Expand Up @@ -477,6 +492,8 @@ dtype <- adpc_aval %>%
) %>%
derive_vars_dtm_to_dt(exprs(PCRFTDTM)) %>%
derive_vars_dtm_to_tm(exprs(PCRFTDTM))
reactable(dtype)
```

### Combine Original and DTYPE Copy
Expand Down Expand Up @@ -593,6 +610,8 @@ adpc <- adpc_prefinal %>%
check_ct_data(metacore) %>% # 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
reactable(adpc)
```

## Apply Labels and Formats with xportr
Expand Down

0 comments on commit 7432194

Please sign in to comment.