xlr_integer: 'xlr_integer' vector

View source: R/xlr_integer.R

xlr_integerR Documentation

xlr_integer vector

Description

This creates an integer vector that will be printed neatly and can easily be exported to Excel using it's native format.You can convert a vector back to its base type with as_base_r().

Usage

xlr_integer(x = integer(), style = xlr_format_numeric())

is_xlr_integer(x)

as_xlr_integer(x, style = xlr_format_numeric())

Arguments

x

A numeric vector

  • For xlr_integer(): A numeric vector

  • For is_xlr_integer(): An object to test

  • For as_xlr_integer() : a vector

style

Additional styling options for the vector. See xlr_format_numeric for more details.

Details

Internally, xlr_integer uses vec_cast to convert numeric types to integers. Anything that vec_cast can handle so can xlr_integer. Read more about casting at vec_cast.

Value

An S3 vector of class xlr_integer

See Also

xlr_vector(), xlr_percent(), xlr_numeric()

Examples

library(xlr)
# Create a variable to represent an integer
x <- xlr_integer(2)
# This will print nicely
x
# You can change the styling, which affects how it looks when we save it as an
# `Excel` document
x <- xlr_integer(x, style = xlr_format(font_size = 9, font_colour = "red"))
x
# We can also define a vector of integers
y <- xlr_integer(c(1,2,3))
y
# You can convert existing data to a integer using dplyr verbs
# It formats large numbers nicely
df <- data.frame(col_1 = c(1:100*100))
df |>
  dplyr::mutate(col_pct = as_xlr_integer(col_1))
# You can use as_xlr_integer to convert a string in a integer
df <- data.frame(col_str = c("12","13","14"))
# now we can convert the string to a integer(), internally it uses the same
# logic as as.integer()
df |>
  dplyr::mutate(col_percent = as_xlr_integer(col_str))

xlr documentation built on April 3, 2025, 6:07 p.m.