Learn R Programming

table.glue (version 0.0.5)

table_glue: Expressive rounding for table values

Description

Expressive rounding for table values

Usage

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

Value

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

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.

See Also

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

Examples

Run this code

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, ]
)

Run the code above in your browser using DataLab