locale {gt} | R Documentation |
Localize formatting and symbols
Description
Localize formatting and symbols
Specify locale
gt()
, some cols_*()
and fmt_*()
functions have a locale
argument.
You can pass locale
as a 2 letters string or 4. (e.g. "fr"
for French,
"pt-BR"
for Brazilian Portuguese). gt also resolves different spellings
internally as much as possible. For example "en_GB"
will work out of the
box.
Range of action of locale
One of the advantage of using gt its consistency in using symbols and currencies in multiple languages
There are two ways to localize your results with gt.
Passing it globally
gt(locale = "<locale>")
Will localize everything possible in the gt()
pipeline.
In individual
fmt_()
functionsLocalize buttons in
opt_interactive()
Will only affect the output of one specific function (or override global setting).
locale
has very low precedence usually. As soon as you override some parameteres,
sep_mark
, dec_mark
, incl_space
, they will be override locale
.
See Also
Examples
# The Spanish locale uses `.` as thousands sep (English uses ,), and
# uses , as the decimal mark
# Using the locale in gt() will format automatically all output in subsequent
# fmt_*() calls.
exibble %>%
gt(locale = "es-AR") %>%
fmt_number()
# Only format currency as mexican peso
exibble %>%
gt(locale = "fr") %>%
fmt_currency(currency, locale = "es-MX")
# will use sep_mark provided
exibble %>%
gt(locale = "fr") %>%
fmt_currency(currency, sep_mark = "", locale = "es-MX")
# Use your imagination, and mix and match.