|
7 | 7 | #' ## Default locale |
8 | 8 | #' |
9 | 9 | #' The default locale used by `arrange()` is the C locale. This is used when |
10 | | -#' `.locale = NULL` unless the `dplyr.legacy_locale` global option is set to |
11 | | -#' `TRUE`. You can also force the C locale to be used unconditionally with |
12 | | -#' `.locale = "C"`. |
| 10 | +#' `.locale = NULL` unless the deprecated `dplyr.legacy_locale` global option is |
| 11 | +#' set to `TRUE`. You can also force the C locale to be used unconditionally |
| 12 | +#' with `.locale = "C"`. |
13 | 13 | #' |
14 | 14 | #' The C locale is not exactly the same as English locales, such as `"en"`. The |
15 | 15 | #' main difference is that the C locale groups the English alphabet by _case_, |
|
31 | 31 | #' |
32 | 32 | #' ## Legacy behavior |
33 | 33 | #' |
34 | | -#' Prior to dplyr 1.1.0, character columns were ordered in the system locale. If |
35 | | -#' you need to temporarily revert to this behavior, you can set the global |
36 | | -#' option `dplyr.legacy_locale` to `TRUE`, but this should be used sparingly and |
37 | | -#' you should expect this option to be removed in a future version of dplyr. It |
38 | | -#' is better to update existing code to explicitly use `.locale` instead. Note |
39 | | -#' that setting `dplyr.legacy_locale` will also force calls to [group_by()] to |
40 | | -#' use the system locale when internally ordering the groups. |
| 34 | +#' `r lifecycle::badge("deprecated")` |
41 | 35 | #' |
42 | | -#' Setting `.locale` will override any usage of `dplyr.legacy_locale`. |
| 36 | +#' Prior to dplyr 1.1.0, character columns were ordered in the system locale. |
| 37 | +#' Setting the global option `dplyr.legacy_locale` to `TRUE` retains this legacy |
| 38 | +#' behavior, but this has been deprecated. Update existing code to explicitly |
| 39 | +#' call `arrange(.locale = )` instead. Run `Sys.getlocale("LC_COLLATE")` to |
| 40 | +#' determine your system locale, and compare that against the list in |
| 41 | +#' [stringi::stri_locale_list()] to find an appropriate value for `.locale`, |
| 42 | +#' i.e. for American English, `"en_US"`. |
| 43 | +#' |
| 44 | +#' Setting `.locale` directly will override any usage of `dplyr.legacy_locale`. |
43 | 45 | #' |
44 | 46 | #' @name dplyr-locale |
45 | 47 | #' @keywords internal |
|
64 | 66 | #' |
65 | 67 | #' # Using `"da"` for Danish ordering gives the expected result |
66 | 68 | #' arrange(df, x, .locale = "da") |
67 | | -#' |
68 | | -#' # If you need the legacy behavior of `arrange()`, which respected the |
69 | | -#' # system locale, then you can set the global option `dplyr.legacy_locale`, |
70 | | -#' # but expect this to be removed in the future. We recommend that you use |
71 | | -#' # the `.locale` argument instead. |
72 | | -#' rlang::with_options(dplyr.legacy_locale = TRUE, { |
73 | | -#' arrange(df, x) |
74 | | -#' }) |
75 | 69 | NULL |
76 | 70 |
|
77 | 71 | dplyr_legacy_locale <- function() { |
78 | 72 | # Used to determine if `group_by()` and `arrange()` should use |
79 | 73 | # base R's `order()` for sorting, which respects the system locale and was |
80 | 74 | # our sorting engine pre-1.1.0. |
81 | | - out <- peek_option("dplyr.legacy_locale") %||% FALSE |
| 75 | + option <- peek_option("dplyr.legacy_locale") |
| 76 | + |
| 77 | + if (is_null(option)) { |
| 78 | + # Default behavior uses C locale |
| 79 | + return(FALSE) |
| 80 | + } |
| 81 | + |
| 82 | + # This deprecation is a bit special. Since it is a global option that only the |
| 83 | + # end user would ever set, we set `user_env = globalenv()` so that it always |
| 84 | + # looks like a "direct" usage to lifecycle. This also makes our lives easier, |
| 85 | + # because `user_env` would have to be threaded all the way up through the |
| 86 | + # exported `grouped_df()` function, which is then used in many places |
| 87 | + # throughout dplyr. Additionally, we've bypassed `deprecate_soft()` and gone |
| 88 | + # straight to `deprecate_warn()` since this is only an end user facing option. |
| 89 | + lifecycle::deprecate_warn( |
| 90 | + when = "1.2.0", |
| 91 | + what = I("`options(dplyr.legacy_locale =)`"), |
| 92 | + details = c( |
| 93 | + i = "If needed for `arrange()`, use `arrange(.locale =)` instead.", |
| 94 | + i = "If needed for `group_by() |> summarise()`, follow up with an additional `arrange(.locale =)` call.", |
| 95 | + i = cli::format_inline(paste0( |
| 96 | + "Use {.run Sys.getlocale(\"LC_COLLATE\")} to determine your system locale, ", |
| 97 | + "and compare against {.run stringi::stri_locale_list()} to determine the `.locale` value to use." |
| 98 | + )) |
| 99 | + ), |
| 100 | + user_env = globalenv() |
| 101 | + ) |
82 | 102 |
|
83 | | - if (!is_bool(out)) { |
| 103 | + if (!is_bool(option)) { |
84 | 104 | abort( |
85 | 105 | "Global option `dplyr.legacy_locale` must be a single `TRUE` or `FALSE`.", |
86 | 106 | call = NULL |
87 | 107 | ) |
88 | 108 | } |
89 | 109 |
|
90 | | - out |
| 110 | + option |
91 | 111 | } |
92 | 112 |
|
93 | 113 | has_minimum_stringi <- function() { |
|
0 commit comments