Skip to content

Commit

Permalink
update using styler
Browse files Browse the repository at this point in the history
  • Loading branch information
elong0527 committed Oct 26, 2023
1 parent f4fd1a0 commit 3ce2706
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
10 changes: 5 additions & 5 deletions R/interactive_table1.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ interactive_table1 <- function(meta,
type = NULL,
max_row = 50000,
...) {

download <- match.arg(download, choices = c("none", "listing", "table", "all"))

if(is.null(type)){
if (is.null(type)) {
type <- ifelse(any(duplicated(
meta$data_observation[[meta$population[[1]]$id]])), "Records", "Subjects")
meta$data_observation[[meta$population[[1]]$id]]
)), "Records", "Subjects")
}

par <- metalite::collect_adam_mapping(meta, parameter)$var
Expand All @@ -25,7 +25,7 @@ interactive_table1 <- function(meta,
}

listing <- nrow(meta$data_population) <= max_row
if(! listing){
if (!listing) {
message("Drill-down listing is not provided because there are more than ", max_row, " rows in the datasets")
}

Expand Down Expand Up @@ -87,7 +87,7 @@ interactive_table1 <- function(meta,
col_def <- reactable::colDef(name = "")
}

if(! keep_total){
if (!keep_total) {
tbl$table <- tbl$table[-1, ]
}

Expand Down
10 changes: 5 additions & 5 deletions R/metalite_table1.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @param type a character value to control section title (e.g. "Subjects", "Records").
#'
#' @examples
#' if(interactive()){
#' if (interactive()) {
#' metalite_table1(~ AGE + SEX | TRT01A, data = r2rtf::r2rtf_adsl, id = "SUBJID")
#' }
#'
Expand All @@ -22,8 +22,7 @@ metalite_table1 <- function(formula,
total = TRUE,
download = "none",
type = NULL) {

if(nrow(data) == 0){
if (nrow(data) == 0) {
stop("There is no records in the input dataset")
}

Expand Down Expand Up @@ -96,7 +95,8 @@ metalite_table1 <- function(formula,
meta,
var_listing = var_listing,
download = download,
type = type))
type = type
))
)
}

Expand All @@ -105,6 +105,6 @@ metalite_table1 <- function(formula,
#' @param x an output from `metalite_table1`.
#'
#' @export
metalite_table1_to_html <- function(x){
metalite_table1_to_html <- function(x) {
cat(htmltools::doRenderTags(x))
}
38 changes: 19 additions & 19 deletions vignettes/metalite-table1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ metalite_table1(
~ AGE + SEX + RACE + BMIBLGR1 | ARM, # formula
data = df, # source data
id = "USUBJID" # unique subject id
)
)
```


Expand Down Expand Up @@ -102,9 +102,10 @@ 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)"))
df,
var = c("AGE", "BMIBLGR1"),
label = c("Age (Year)", "BMI Group (kg/m2)")
)
metalite::get_label(df)
```
Expand All @@ -114,22 +115,22 @@ for example, "Number of Participants".

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

## Total Column

The `Total` column can be hided.

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

## Download Data
Expand All @@ -138,11 +139,11 @@ 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 | ARM,
data = df,
metalite_table1(~ AGE + SEX | ARM,
data = df,
id = "USUBJID",
download = "listing"
)
)
```

## Rmarkdown Render
Expand All @@ -153,17 +154,16 @@ we need to clearly call the `print` function and
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){
type <- c("Subjects", "Records")
for (i in 1:2) {
cat("### Table ", i, "\n")
tbl <- metalite_table1(~ AGE + SEX | ARM,
data = df,
tbl <- metalite_table1(~ AGE + SEX | ARM,
data = df,
id = "USUBJID",
type = type[i]
)
metalite_table1_to_html(tbl)
}
```
Expand Down

0 comments on commit 3ce2706

Please sign in to comment.