It's possible to move a set of columns to the end of the column series, we
only need to specify which columns
are to be moved. While this can be done
upstream of gt, this function makes to process much easier and it's less
error prone. The ordering of the columns
that are moved to the end is
preserved (same with the ordering of all other columns in the table).
Arguments
- data
The gt table data object
obj:<gt_tbl>
--- requiredThis is the gt table object that is commonly created through use of the
gt()
function.- columns
Columns to target
<column-targeting expression>
--- default:everything()
The columns for which the moving operations should be applied. Can either be a series of column names provided in
c()
, a vector of column indices, or a select helper function. Examples of select helper functions includestarts_with()
,ends_with()
,contains()
,matches()
,one_of()
,num_range()
, andeverything()
. The columns move as a group to the right-most side of the table. The order of the remaining columns will be preserved.
Details
The columns supplied in columns
must all exist in the table. If you need to
place one or columns at the start of the column series, the
cols_move_to_start()
function should be used. More control is offered with
the cols_move()
function, where columns could be placed after a specific
column.
Examples
Use a portion of the countrypops
dataset to create a gt table. Let's
move the year
column to the end of the column series with the
cols_move_to_end()
function.
countrypops |>
dplyr::select(-contains("code")) |>
dplyr::filter(country_name == "Mongolia") |>
tail(5) |>
gt() |>
cols_move_to_end(columns = year)
Let's again use countrypops
for a gt example table. This time we'll
move the year
and country_name
columns to the end of the column series.
countrypops |>
dplyr::select(-contains("code")) |>
dplyr::filter(country_name == "Mongolia") |>
tail(5) |>
gt() |>
cols_move_to_end(columns = c(year, country_name))
See also
Other column modification functions:
cols_align_decimal()
,
cols_align()
,
cols_hide()
,
cols_label_with()
,
cols_label()
,
cols_merge_n_pct()
,
cols_merge_range()
,
cols_merge_uncert()
,
cols_merge()
,
cols_move_to_start()
,
cols_move()
,
cols_unhide()
,
cols_width()