Huxtable can be used with dplyr verbs dplyr::select()
, dplyr::rename()
,
dplyr::relocate()
, dplyr::slice()
, dplyr::arrange()
, dplyr::mutate()
and dplyr::transmute()
. These will return huxtables. Other verbs like
dplyr::summarise()
will simply return data frames as normal;
dplyr::pull()
will return a vector. mutate
has an extra option, detailed
below.
mutate.huxtable(.data, ..., copy_cell_props = TRUE)
A huxtable.
Arguments passed to dplyr::mutate()
.
Logical: copy cell and column properties from existing columns.
If mutate
creates new columns, and the argument copy_cell_props
is missing or TRUE
, then cell and column properties will be copied from
existing columns to their left, if there are any. Otherwise, they will be the
standard defaults. Row and table properties, and properties of cells in
existing columns, remain unchanged.
ht <- hux(a = 1:5, b = 1:5, c = 1:5, d = 1:5, add_colnames = FALSE)
bold(ht)[c(1, 3), ] <- TRUE
bold(ht)[, 1] <- TRUE
ht2 <- dplyr::select(ht, b:c)
ht2
#> 1 1
#> 2 2
#> 3 3
#> 4 4
#> 5 5
#>
#> Column names: b, c
bold(ht2)
#> b c
#> 1 TRUE TRUE
#> 2 FALSE FALSE
#> 3 TRUE TRUE
#> 4 FALSE FALSE
#> 5 FALSE FALSE
ht3 <- dplyr::mutate(ht, x = a + b)
ht3
#> 1 1 1 1 2
#> 2 2 2 2 4
#> 3 3 3 3 6
#> 4 4 4 4 8
#> 5 5 5 5 10
#>
#> Column names: a, b, c, d, x
bold(ht3)
#> a b c d x
#> 1 TRUE TRUE TRUE TRUE TRUE
#> 2 TRUE FALSE FALSE FALSE FALSE
#> 3 TRUE TRUE TRUE TRUE TRUE
#> 4 TRUE FALSE FALSE FALSE FALSE
#> 5 TRUE FALSE FALSE FALSE FALSE
ht4 <- dplyr::mutate(ht, x = a + b,
copy_cell_props = FALSE)
bold(ht4)
#> a b c d x
#> 1 TRUE TRUE TRUE TRUE FALSE
#> 2 TRUE FALSE FALSE FALSE FALSE
#> 3 TRUE TRUE TRUE TRUE FALSE
#> 4 TRUE FALSE FALSE FALSE FALSE
#> 5 TRUE FALSE FALSE FALSE FALSE