Skip to content

Commit

Permalink
Change default locale to en
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Oct 16, 2016
1 parent 494f149 commit 5779506
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 23 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# stringr 1.1.0.9000

* All functions that take a locale (e.g. `str_to_lower()` and `str_sort()`)
default to "en" (English) to ensure that the default is consistent across
platforms.

* `str_order()` and `str_sort()` gain explicit `numeric` argument for sorting
mixed numbers and strings.

Expand Down
11 changes: 6 additions & 5 deletions R/case.R
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
#' Convert case of a string.
#'
#' @param string String to modify
#' @param locale Locale to use for translations.
#' @param locale Locale to use for translations. Defaults to "en" (English)
#' to ensure consistent default ordering across platforms.
#' @examples
#' dog <- "The quick brown dog"
#' str_to_upper(dog)
#' str_to_lower(dog)
#' str_to_title(dog)
#'
#' # Locale matters!
#' str_to_upper("i", "en") # English
#' str_to_upper("i") # English
#' str_to_upper("i", "tr") # Turkish
#' @name case
NULL

#' @export
#' @rdname case
str_to_upper <- function(string, locale = "") {
str_to_upper <- function(string, locale = "en") {
stri_trans_toupper(string, locale = locale)
}
#' @export
#' @rdname case
str_to_lower <- function(string, locale = "") {
str_to_lower <- function(string, locale = "en") {
stri_trans_tolower(string, locale = locale)
}
#' @export
#' @rdname case
str_to_title <- function(string, locale = "") {
str_to_title <- function(string, locale = "en") {
stri_trans_totitle(string, opts_brkiter = stri_opts_brkiter(locale = locale))
}
4 changes: 3 additions & 1 deletion R/modifiers.r
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ fixed <- function(pattern, ignore_case = FALSE) {
#' @rdname modifiers
#' @param locale Locale to use for comparisons. See
#' \code{\link[stringi]{stri_locale_list}()} for all possible options.
#' Defaults to "en" (English) to ensure that the default collation is
#' consistent across platforms.
#' @param ... Other less frequently used arguments passed on to
#' \code{\link[stringi]{stri_opts_collator}},
#' \code{\link[stringi]{stri_opts_regex}}, or
#' \code{\link[stringi]{stri_opts_brkiter}}
coll <- function(pattern, ignore_case = FALSE, locale = NULL, ...) {
coll <- function(pattern, ignore_case = FALSE, locale = "en", ...) {
if (!is_bare_character(pattern)) {
stop("Can only modify plain character vectors.", call. = FALSE)
}
Expand Down
11 changes: 6 additions & 5 deletions R/sort.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
#' @param na_last Where should \code{NA} go? \code{TRUE} at the end,
#' \code{FALSE} at the beginning, \code{NA} dropped.
#' @param locale In which locale should the sorting occur? Defaults to
#' the current locale.
#' the English. This ensures that code behaves the same way across
#' platforms.
#' @param numeric If \code{TRUE}, will sort digits numerically, instead
#' of as strings.
#' @param ... Other options used to control sorting order. Passed on to
#' \code{\link[stringi]{stri_opts_collator}}.
#' @seealso \code{\link[stringi]{stri_order}} for the underlying implementation.
#' @export
#' @examples
#' str_order(letters, locale = "en")
#' str_sort(letters, locale = "en")
#' str_order(letters)
#' str_sort(letters)
#'
#' str_order(letters, locale = "haw")
#' str_sort(letters, locale = "haw")
Expand All @@ -24,15 +25,15 @@
#' str_sort(x)
#' str_sort(x, numeric = TRUE)
str_order <- function(x, decreasing = FALSE, na_last = TRUE,
locale = "", numeric = FALSE, ...) {
locale = "en", numeric = FALSE, ...) {
stri_order(x, decreasing = decreasing, na_last = na_last,
opts_collator = stri_opts_collator(locale, numeric = numeric, ...))
}

#' @export
#' @rdname str_order
str_sort <- function(x, decreasing = FALSE, na_last = TRUE,
locale = "", numeric = FALSE, ...) {
locale = "en", numeric = FALSE, ...) {
stri_sort(x, decreasing = decreasing, na_last = na_last,
opts_collator = stri_opts_collator(locale, numeric = numeric, ...))
}
11 changes: 6 additions & 5 deletions man/case.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/modifiers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions man/str_order.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5779506

Please sign in to comment.