xlr_integer | R Documentation |
xlr_integer
vectorThis 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()
.
xlr_integer(x = integer(), style = xlr_format_numeric())
is_xlr_integer(x)
as_xlr_integer(x, style = xlr_format_numeric())
x |
A numeric vector
|
style |
Additional styling options for the vector. See xlr_format_numeric for more 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.
An S3 vector of class xlr_integer
xlr_vector()
, xlr_percent()
, xlr_numeric()
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.