Skip to content

Commit

Permalink
Merge pull request #41 from Merck/DEVR-3462function-for-baseline-char…
Browse files Browse the repository at this point in the history
…acteristics-table-by-subgroup

Fix the functions for baseline characteristics table by subgroup and re-generate the tables
  • Loading branch information
wangben718 authored Oct 1, 2024
2 parents bbfd54f + 5bc1012 commit 9354df9
Show file tree
Hide file tree
Showing 5 changed files with 659 additions and 110 deletions.
2 changes: 1 addition & 1 deletion R/format_base_char_subgroup.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ format_base_char_subgroup <- function(
# tbl <- tbl[, -which(names(tbl) %in% rm_tot)]
#}

outdata$tbl <- tbl |> dplyr::arrange(order)
outdata$tbl <- tbl[order(tbl$order),]
outdata$display <- display
outdata$display_stat <- display_stat
outdata
Expand Down
11 changes: 2 additions & 9 deletions R/rtf_base_char_subgroup.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,8 @@ rtf_base_char_subgroup <- function(

out_all <- outdata$out_all
tbl <- outdata$tbl

#Add empty line before stats summary section
tbl<- tbl |>
dplyr::mutate(split = cumsum(ifelse(tolower(name) == outdata$display_stat[1], 1, 0))) |>
dplyr::group_by(split) |>
dplyr::group_modify(.f = ~dplyr::add_row(.data = .,
name = "", var_label= tbl[tolower(tbl$name) == outdata$display_stat[1],]$var_label))

tbl1 <- tbl[!names(tbl) %in% c("order","split")]

tbl1 <- tbl[!names(tbl) %in% c("order")]
tgroup <- outdata$group
sgroup <- outdata$subgroup
if (outdata$display_subgroup_total) tgroup <- c(tgroup, "Total")
Expand Down
19 changes: 9 additions & 10 deletions vignettes/baseline-character.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ outdata$tbl
outdata |> rtf_base_char(
source = "Source: [CDISCpilot: adam-adsl]",
path_outdata = tempfile(fileext = ".Rdata"),
path_outtable = "base_char.rtf"
path_outtable = "outtable/base0char.rtf"
)
```

Expand Down Expand Up @@ -205,7 +205,7 @@ raw datasets. Key arguments are:
- `subgroup_var`: a character value of subgroup variable name in observation data saved in meta$data_observation.
- `subgroup_header`: a character vector for column header hierarchy. The first element will be the first level header and the second element will be second level header.

```{r, eval = FALSE}
```{r}
outdata <- prepare_base_char_subgroup(
meta,
population = "apat",
Expand All @@ -218,22 +218,22 @@ outdata <- prepare_base_char_subgroup(

The output dataset contains commonly used statistics within each `subgroup_var`.

```{r, eval = FALSE}
```{r}
outdata$out_all$`Placebo`
outdata$out_all$`High Dose`
outdata$out_all$`Low Dose`
```

The information about subgroup saved with `outdata$group` and `outdata$subgroup`.

```{r, eval = FALSE}
```{r}
outdata$group
outdata$subgroup
```

`n_pop`: participants in population within each `subgroup_var`.

```{r, eval = FALSE}
```{r}
outdata$out_all$`Placebo`$n
outdata$out_all$`High Dose`$n
outdata$out_all$`Low Dose`$n
Expand All @@ -243,7 +243,7 @@ outdata$out_all$`Low Dose`$n

`format_base_char_subgroup` to prepare analysis dataset before generate RTF output

```{r, eval = FALSE}
```{r}
tbl <- format_base_char_subgroup(outdata)
head(tbl$tbl)
```
Expand All @@ -252,12 +252,11 @@ head(tbl$tbl)

`rtf_base_char_subgroup` to generate RTF output

```{r, warning=FALSE, eval = FALSE}
outdata |>
format_base_char_subgroup() |>
```{r, warning=FALSE}
outdata <- format_base_char_subgroup(outdata) |>
rtf_base_char_subgroup(
source = "Source: [CDISCpilot: adam-adsl]",
path_outdata = tempfile(fileext = ".Rdata"),
path_outtable = "base_char_subgroup.rtf"
path_outtable = "outtable/base0charsubgroup.rtf"
)
```
Loading

0 comments on commit 9354df9

Please sign in to comment.