Skip to content

Commit

Permalink
vignette updates and clean up R CMD check notes
Browse files Browse the repository at this point in the history
  • Loading branch information
mstackhouse committed Dec 15, 2023
1 parent 0f01ebc commit 1f26ff6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 21 deletions.
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export(apply_conditional_format)
export(apply_formats)
export(apply_row_masks)
export(build)
export(collapse_row_labels)
export(f_str)
export(get_by)
export(get_count_layer_formats)
Expand Down Expand Up @@ -138,6 +139,7 @@ importFrom(dplyr,bind_rows)
importFrom(dplyr,case_when)
importFrom(dplyr,cur_column)
importFrom(dplyr,cur_group)
importFrom(dplyr,desc)
importFrom(dplyr,distinct)
importFrom(dplyr,do)
importFrom(dplyr,everything)
Expand All @@ -160,10 +162,12 @@ importFrom(dplyr,rename)
importFrom(dplyr,row_number)
importFrom(dplyr,rowwise)
importFrom(dplyr,select)
importFrom(dplyr,slice_head)
importFrom(dplyr,summarize)
importFrom(dplyr,tally)
importFrom(dplyr,ungroup)
importFrom(dplyr,vars)
importFrom(dplyr,where)
importFrom(forcats,fct_collapse)
importFrom(forcats,fct_drop)
importFrom(forcats,fct_expand)
Expand All @@ -177,6 +181,7 @@ importFrom(purrr,flatten)
importFrom(purrr,imap)
importFrom(purrr,map)
importFrom(purrr,map2)
importFrom(purrr,map2_chr)
importFrom(purrr,map2_dfr)
importFrom(purrr,map_chr)
importFrom(purrr,map_dbl)
Expand Down
2 changes: 2 additions & 0 deletions R/collapse_row_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#'
#' @param .x The number of levels to indent
#' @param .y Input variable for which indentation will be done
#' @param indent Indentation string to be used, which is multiplied at each indentation level
#'
#' @return Character string with indentation applied
#' @noRd
add_indentation <- function(.x, .y, indent = " ") {
paste(c(rep("",.x-1), .y), collapse=indent)
}
Expand Down
9 changes: 7 additions & 2 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#' @importFrom rlang expr exprs enexprs enexpr is_named env_parent env_label is_logical is_empty is_quosures quo_is_symbol sym syms := as_name
#' @importFrom rlang quos quo env_names env_bind_active as_label eval_tidy warn quo_is_call
#' @importFrom stringr str_split str_extract_all regex str_detect str_replace_all str_replace str_locate_all fixed str_count str_trim str_wrap
#' @importFrom purrr flatten map map_lgl pmap_chr imap reduce map_chr map_int map_dbl map_dfr pmap_dfr walk2 map2 map2_dfr walk
#' @importFrom purrr flatten map map_lgl pmap_chr imap reduce map_chr map_int map_dbl map_dfr pmap_dfr walk2 map2 map2_dfr map2_chr walk
#' @importFrom stringr str_sub str_sub<- str_extract str_pad str_starts str_remove_all str_match_all
#' @importFrom tidyr pivot_longer pivot_wider replace_na
#' @importFrom magrittr %>% extract extract2
#' @importFrom assertthat assert_that
#' @importFrom stats IQR median sd quantile var
#' @importFrom dplyr n summarize filter vars tally ungroup group_by mutate lag select bind_rows full_join add_tally distinct rowwise
#' @importFrom dplyr everything rename mutate_at mutate_all as_tibble bind_cols do case_when arrange left_join row_number between mutate_if
#' @importFrom dplyr across anti_join n_distinct if_else group_keys cur_group cur_column pull matches
#' @importFrom dplyr across anti_join n_distinct if_else group_keys cur_group cur_column pull matches slice_head where desc
#' @importFrom tidyr complete nesting pivot_wider pivot_longer replace_na starts_with fill
#' @importFrom utils str head tail
#' @importFrom tidyselect all_of vars_select any_of
Expand Down Expand Up @@ -303,3 +303,8 @@ l <- NULL
w <- NULL
s <- NULL
out <- NULL
og_row <- NULL
desc <- NULL
id <- NULL
stub_sort <- NULL

19 changes: 0 additions & 19 deletions man/add_indentation.Rd

This file was deleted.

32 changes: 32 additions & 0 deletions vignettes/post_processing.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,38 @@ There are a few considerations when using `apply_row_masks()`:
- This function is order dependent, so make sure your data are sorted before submitting to `apply_row_masks()`
- When inserting row breaks, by default the Tpylr variable `ord_layer_index` is used. You can submit other variables via the ellipsis parameter (`...`) if you'd like to use a different variable grouping to insert rows

## Collapsing Row Labels

Different table formats call for different handling of row labels, depending on the preferences of an individual organization and the specifics of the table at hand. **Tplyr** inherently creates row labels as separate columns, but similar to the way that count layers nest the inner and the outer layer, we also offer the `collapse_row_labels()` function to pull multiple row labels into a single column.

```{r collapse_row_labels}
dat <- tplyr_table(adsl, TRT01P) %>%
add_layer(
group_count(RACE, by = vars("Race n (%)", SEX))
) %>%
add_layer(
group_desc(AGE, by = vars("Age (years)", SEX))
) %>%
build()
collapse_row_labels(dat, row_label1, row_label2, row_label3) %>%
select(row_label, var1_Placebo)
```
By default, indentation is set to 2 spaces, but by using the `indent` parameter you can change this to any string you desire.

```{r collapse_row_labels2}
collapse_row_labels(dat, row_label1, row_label2, row_label3, indent = "&nbsp;&nbsp;") %>%
select(row_label, var1_Placebo) %>%
kable(escape=FALSE)
```
You also have control over which columns you collapse, allowing you to keep separate row labels if you don't want all collapsed together

```{r collapse_row_labels3}
collapse_row_labels(dat, row_label1, row_label2, indent = "&nbsp;&nbsp;") %>%
select(row_label, row_label3, var1_Placebo) %>%
kable(escape=FALSE)
```

## Conditional Formatting

In some circumstances, like `add_total_row()`, **Tplyr** lets you specify special formats separate from those in `set_format_strings()`. But within the table body there's no other way to set specific, conditional formats based on the table data itself. To address this, we've added the post-processing function `apply_conditional_format()` to allow you to set conditional formats on result cells.
Expand Down

0 comments on commit 1f26ff6

Please sign in to comment.