format_cols: Format columns for printing

Description Usage Arguments Value See Also Examples

View source: R/formatting.R

Description

Wraps around base::format() and dplyr::mutate() to format columns of a tibble or data.frame. Note that any formatted columns will be converted to character mode, so use this function only for printing.

Usage

1
format_cols(.data, .cols = NULL, ...)

Arguments

.data

A data.frame or tibble.

.cols

<tidy-select> columns to format. If NULL (the default), will format all double columns.

...

Arguments passed on to format

Value

An object of the same type as .data with any formatted columns converted to character mode.

See Also

format

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Convert to tibble for better printing
mtcars_tbl <- tibble::as_tibble(mtcars)

## Formatting all columns
format_cols(mtcars_tbl, digits = 0)

## Specific columns
format_cols(mtcars_tbl, c("wt", "qsec"), digits = 0)

## Other formatting options
format_cols(mtcars_tbl, scientific = TRUE)

format_cols(mtcars_tbl, trim = TRUE)

milanmlft/MMmotley documentation built on Feb. 4, 2022, 7:42 a.m.