table_glue: Expressive rounding for table values

View source: R/table_glue.R

table_glueR Documentation

Expressive rounding for table values

Description

Expressive rounding for table values

Usage

table_glue(..., rspec = NULL, .sep = "", .envir = parent.frame())

Arguments

...

strings to round and format. Multiple inputs are concatenated together. Named arguments are not supported.

rspec

a rounding_specification object. If no rspec is given, a default setting will round values to decimal places based on the magnitude of the values.

.sep

Separator used to separate elements

.envir

environment to evaluate each expression in.

Value

a character vector of length equal to the vectors supplied in ...

See Also

Other table helpers: table_ester(), table_pvalue(), table_value()

Examples


x <- runif(10)
y <- runif(10)

table_glue("{x} / {y} = {x/y}")

table_glue("{x}", "({100 * y}%)", .sep = ' ')

df = data.frame(x = 1:10, y=1:10)

table_glue("{x} / {y} = {as.integer(x/y)}", .envir = df)
table_glue("{x} / {y} = {as.integer(x/y)}")

with(df, table_glue("{x} / {y} = {as.integer(x/y)}"))

mtcars$car <- rownames(mtcars)
# use the default rounding specification
table_glue(
  "the {car} gets ~{mpg} miles/gallon and weighs ~{wt} thousand lbs",
  .envir = mtcars[1:3, ]
)

# use your own rounding specification
rspec <- round_spec()
rspec <- round_using_decimal(rspec, digits = 1)

table_glue(
  "the {car} gets ~{mpg} miles/gallon and weighs ~{wt} thousand lbs",
  rspec = rspec,
  .envir = mtcars[1:3, ]
)

table.glue documentation built on Feb. 16, 2023, 9:29 p.m.