The prj_project() function is designed to take in a dataframe made up of projectable_cols, and to 'project' it into an ordinary dataframe as per the instructions provided in the shadow attribute of each column. The prj_gt() function does the same thing, but initialises a gt object for display.

prj_project(.data, .cols = list(), .digits = getOption("prj_digits"))

prj_gt(
  .data,
  .cols = list(),
  .digits = getOption("prj_digits"),
  rowgroup_col = "row_spanner",
  rowname_col = "rows",
  ...
)

prj_flex(.data, .cols = list(), .digits = getOption("prj_digits"))

Arguments

.data

A dataframe, ideally one containing projectable_cols

.cols

A named list. Each name should be the name of a column in .data; each value should be a named character vector containing glue-like specifications for the output columns.

.digits

A number representing the number of digits to round each numeric value to. If NULL no rounding will be performed

rowgroup_col

The name of a column in .data to group rows by; if NULL no grouping will be used.

rowname_col

The name of a column in .data to take as the row labels; if NULL no row labels will be applied

...

Additional arguments to pass on to gt::gt()

Value

a projection object

Details

The shadow attribute of each column can be set via the .cols argument of prj_project() or by using the prj_shadow() helper function.

The projection output will also come attached with metadata which keeps track of which columns in the output belong to which columns in the input.

Examples

# Create a table made up of `projectable_col`s
my_tbl <- prj_tbl_rows(
  .data = mtcars,
  Cylinders = cyl,
  Transmission = list(Automatic = am %in% 0, Manual = am %in% 1),
)

my_tbl <- prj_tbl_cols(
  .data = my_tbl,
  `V-Shaped` = col_freq(n = vs %in% 1, N = vs %in% 0:1),
  `Not V-shaped` = col_freq(n = vs %in% 0, N = vs %in% 0:1)
)

my_tbl <- prj_tbl_summarise(.data = my_tbl)

# Project it back into an ordinary dataframe
prj_project(my_tbl, list(
  `V-Shaped` = "{signif(p, 2)} ({n})",
  `Not V-shaped` = "{signif(p, 2)} ({n})"
))
#> # A tibble: 5 × 4
#>   row_spanner  rows      `V-Shaped` `Not V-shaped`
#> * <col_row>    <col_row> <glue>     <glue>        
#> 1 Cylinders    4         0.91 (10)  0.09 (1)      
#> 2 Cylinders    6         0.57 (4)   0.43 (3)      
#> 3 Cylinders    8         0 (0)      1 (14)        
#> 4 Transmission Automatic 0.37 (7)   0.63 (12)     
#> 5 Transmission Manual    0.54 (7)   0.46 (6)      

# Produce a `gt` display object
out <- prj_gt(my_tbl, list(
  `V-Shaped` = "{signif(p, 2)} ({n})",
  `Not V-shaped` = "{signif(p, 2)} ({n})"
))

#' # Produce a `flextable` display object
out <- prj_flex(my_tbl, list(
  `V-Shaped` = "{signif(p, 2)} ({n})",
  `Not V-shaped` = "{signif(p, 2)} ({n})"
))