From 4960543e9ba8cf6aff4daccc4f8166e66664d3c0 Mon Sep 17 00:00:00 2001 From: olivroy Date: Fri, 27 Sep 2024 16:51:29 -0400 Subject: [PATCH] Add `gt.locale` option --- NEWS.md | 2 ++ R/gt.R | 5 +++-- R/zzz.R | 2 ++ man/gt-options.Rd | 2 ++ man/gt.Rd | 7 ++++--- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 48f37ef67b..558de0c1e5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,8 @@ * PDF output now defaults to a full-width floating environment using `tabular*` (@AronGullickson, #1588). Float position can be controlled by the `latex.tbl.pos` argument in `tab_options`. Quarto users can alternatively use the `tbl-pos` argument to control positioning. To use a `longtable` environment instead, use `tab_option(latex.use_longtable = TRUE)`. +* The `locale` argument of `gt()` now defaults to `getOption("gt.locale")` if set (#1894). + ## Interactive table support * Interactive tables will show no border if `opt_table_lines(extent = "none")` is specified (#1307). diff --git a/R/gt.R b/R/gt.R index 79b5f47cb0..b2bd19017a 100644 --- a/R/gt.R +++ b/R/gt.R @@ -120,12 +120,13 @@ #' #' @param locale *Locale identifier* #' -#' `scalar` // *default:* `NULL` (`optional`) +#' `scalar` // *default:* `getOption("gt.locale")` (`optional`) #' #' An optional locale identifier that can be set as the default locale for all #' functions that take a `locale` argument. Examples include `"en"` for #' English (United States) and `"fr"` for French (France). We can call #' [info_locales()] as a useful reference for all of the locales that are supported. +#' If set, `options(gt.locale)` is also consulted. #' #' @param row_group.sep *Separator text for multiple row group labels* #' @@ -302,7 +303,7 @@ gt <- function( row_group_as_column = FALSE, auto_align = TRUE, id = NULL, - locale = NULL, + locale = getOption("gt.locale"), row_group.sep = getOption("gt.row_group.sep", " - ") ) { diff --git a/R/zzz.R b/R/zzz.R index 08d784f78c..b37a0fce8d 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -138,6 +138,8 @@ utils::globalVariables( #' #' **gt** uses the following [options()] to configure behavior: #' +#' - `gt.locale`: A [locale][info_locales()] to yse by default in +#' the [gt()] function. #' - `gt.row_group.sep`: A separator between groups for the row group label. By #' default this is `" - "`. #' - `gt.html_tag_check`: A logical scalar indicating whether or not to print a diff --git a/man/gt-options.Rd b/man/gt-options.Rd index ad99e8003a..6aeb6d7f21 100644 --- a/man/gt-options.Rd +++ b/man/gt-options.Rd @@ -11,6 +11,8 @@ \strong{gt} uses the following \code{\link[=options]{options()}} to configure behavior: \itemize{ +\item \code{gt.locale}: A \link[=info_locales]{locale} to yse by default in +the \code{\link[=gt]{gt()}} function. \item \code{gt.row_group.sep}: A separator between groups for the row group label. By default this is \code{" - "}. \item \code{gt.html_tag_check}: A logical scalar indicating whether or not to print a diff --git a/man/gt.Rd b/man/gt.Rd index 0f11e39b54..81d3cab225 100644 --- a/man/gt.Rd +++ b/man/gt.Rd @@ -14,7 +14,7 @@ gt( row_group_as_column = FALSE, auto_align = TRUE, id = NULL, - locale = NULL, + locale = getOption("gt.locale"), row_group.sep = getOption("gt.row_group.sep", " - ") ) } @@ -90,12 +90,13 @@ providing a character value.} \item{locale}{\emph{Locale identifier} -\verb{scalar} // \emph{default:} \code{NULL} (\code{optional}) +\verb{scalar} // \emph{default:} \code{getOption("gt.locale")} (\code{optional}) An optional locale identifier that can be set as the default locale for all functions that take a \code{locale} argument. Examples include \code{"en"} for English (United States) and \code{"fr"} for French (France). We can call -\code{\link[=info_locales]{info_locales()}} as a useful reference for all of the locales that are supported.} +\code{\link[=info_locales]{info_locales()}} as a useful reference for all of the locales that are supported. +If set, \code{options(gt.locale)} is also consulted.} \item{row_group.sep}{\emph{Separator text for multiple row group labels}