Skip to content

Commit

Permalink
- add metalite_table1_to_html.
Browse files Browse the repository at this point in the history
- update vignettes
  • Loading branch information
elong0527 committed Oct 26, 2023
1 parent 167cc69 commit 557de84
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 8 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Generated by roxygen2: do not edit by hand

export(metalite_table1)
export(metalite_table1_to_html)
9 changes: 9 additions & 0 deletions R/metalite_table1.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,12 @@ metalite_table1 <- function(formula,
type = type))
)
}

#' Convert to html
#'
#' @param x an output from `metalite_table1`.
#'
#' @export
metalite_table1_to_html <- function(x){
cat(htmltools::doRenderTags(x))
}
14 changes: 14 additions & 0 deletions man/metalite_table1_to_html.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 96 additions & 8 deletions vignettes/metalite-table1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ contains more details.
The `metalite.table1` provide an interactive table1 to
enhance the communication between statisticians and clinicians.

# Example

We use a subject level dataset `r2rtf::r2rtf_adsl` to create a example interactive table1.

First, we modify the dataset by

- adding a few missing values.
- order the group variables.
- keep relevent variables.

```{r}
# Prepare analysis ready data
df <- r2rtf_adsl
Expand All @@ -46,18 +56,21 @@ df$ARM <- factor(
c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose"),
c("Placebo", "Low Dose", "High Dose")
)
df <- df[, c("USUBJID", "ARM", "AGE", "SEX", "RACE", "BMIBLGR1")]
df[1:6, c("USUBJID", "ARM", "AGE", "SEX", "RACE", "BMIBLGR1")]
head(df)
```

```{r, eval = FALSE}
# Create interactive table1
The interactive table1 can then be created by the `metalite_table1` function.

```{r}
metalite_table1(~ AGE + SEX + RACE + BMIBLGR1 | ARM, # formula for analysis variables and group
data = df, # source data
id = "USUBJID"
) # unique subject id
id = "USUBJID" # unique subject id
)
```


The interactive features are illustrated in the GIF below.

```{r, echo = FALSE}
Expand All @@ -73,10 +86,85 @@ we are able to answer ad-hoc questions from clinicians with interactive features

Those are common questions for ongoing clinical trials.

```{r, eval}
# create table1
table1(~ AGE + SEX + RACE + BMIBLGR1 | ARM, data = df)
# Features

## Section Title

The section title is defined by the column labels.
The `metalite::get_labels` allows you quickly check the label.

```{r}
metalite::get_label(df)
```

The `metalite::assign_labels` can modify labels

```{r}
df <- metalite::assign_label(
df,
var = c("AGE", "BMIBLGR1"),
label = c("Age (Year)", "BMI Group (kg/m2)"))
metalite::get_label(df)
```

The `type` argument can modify the term at the first row,
for example, "Number of Participants".

```{r}
metalite_table1(~ AGE + SEX + RACE + BMIBLGR1 | ARM,
data = df,
id = "USUBJID",
type = "Participants"
)
```

## Total Column

The `Total` column can be hided.

```{r}
metalite_table1(~ AGE + SEX + RACE + BMIBLGR1 | ARM,
data = df,
id = "USUBJID",
total = FALSE
)
```

## Download Data

We can allow user to download raw data, for example we can
set `download="listing"` to enable user download the drill down listing.

```{r}
metalite_table1(~ AGE + SEX + RACE + BMIBLGR1 | ARM,
data = df,
id = "USUBJID",
download = "listing"
)
```

## Rmarkdown Render

Sometimes we want to create multiple tables in a for loop,
we need to clearly call the `print` function and
[output text as raw content](https://bookdown.org/yihui/rmarkdown-cookbook/results-asis.html)
by using `resutls="asis"` (e.g., `{r, results="asis"}`) in the Rmarkdown code chunk.

```{r, results="asis"}
type = c("Subjects", "Records")
for(i in 1:2){
cat("### Table ", i, "\n")
tbl <- metalite_table1(~ AGE + SEX + RACE + BMIBLGR1 | ARM,
data = df,
id = "USUBJID",
type = type[i]
)
metalite_table1_to_html(tbl)
}
```


0 comments on commit 557de84

Please sign in to comment.