xlr_vector: 'xlr_vector' vector

View source: R/xlr_vector.R

xlr_vectorR Documentation

xlr_vector vector

Description

A general container for including additional styling options within a vector so that it can easily be exported to Excel. This vector type should be used for characters, factors, Booleans, complex numbers, etc. It does not support dates.

Usage

xlr_vector(x = vector(), excel_format = "GENERAL", style = xlr_format())

is_xlr_vector(x)

as_xlr_vector(x, excel_format = "GENERAL", style = xlr_format())

Arguments

x

A vector

  • For xlr_vector(): A vector

  • For is_xlr_vector(): An object to test

  • For as_xlr_vector() : a vector

excel_format

a character, the Excel cell format, not validated. See createStyle argument numFmt for more details on what you can specify.

style

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

Details

While you can use it with integer, and double types and specifying the associated Excel format, we recommend using xlr_integer, xlr_numeric, or xlr_percent types instead.

You can convert a vector back to its base type with as_base_r().

Value

An S3 vector of class xlr_vector

See Also

xlr_percent(), xlr_integer(), xlr_numeric(), as_base_r()

Examples

library(xlr)
# Create a xlr_vector object, this is used so we can add styling to an existing
# vector so that it prints nicely in `Excel`
#
# Note currently the style will not change the style in the console
x <- xlr_vector(1:100,
                 excel_format = "00.0##",
                 style = xlr_format(font_size = 8))

# You can also use it so that dates are nicely printed in `Excel`
dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92")
dates <- as.Date(dates, "%m/%d/%y")
x <- xlr_vector(dates,
                 # Print it as a long date in `Excel`
                 excel_format = "LONGDATE")
# You can convert existing data to a xlr_vectors using dplyr verbs
iris |>
  dplyr::mutate(iris_format = as_xlr_vector(Species,
                                             "TEXT",
                                             xlr_format(text_style = "italic")))

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