Skip to content

Commit 592aca1

Browse files
yutannihilationkevinhankens
authored andcommitted
Handle Turkish dotted and dotless i properly (tidyverse#3011)
* Use chartr() instad of toupper() and tolower()
1 parent 828e948 commit 592aca1

File tree

6 files changed

+22
-6
lines changed

6 files changed

+22
-6
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
* Closed arrows in `element_line()` are now filled (@yutannihilation, #2924).
2121

22+
* ggplot2 now works in Turkish locale (@yutannihilation, #3011).
23+
2224
# ggplot2 3.1.0
2325

2426
## Breaking changes

R/fortify-multcomp.r

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fortify.glht <- function(model, data, ...) {
4646
#' @export
4747
fortify.confint.glht <- function(model, data, ...) {
4848
coef <- model$confint
49-
colnames(coef) <- tolower(colnames(coef))
49+
colnames(coef) <- to_lower_ascii(colnames(coef))
5050

5151
plyr::unrowname(base::data.frame(
5252
lhs = rownames(coef),

R/layer.r

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ is.layer <- function(x) inherits(x, "Layer")
341341

342342

343343
check_subclass <- function(x, subclass,
344-
argname = tolower(subclass),
344+
argname = to_lower_ascii(subclass),
345345
env = parent.frame()) {
346346
if (inherits(x, subclass)) {
347347
x

R/save.r

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ plot_dev <- function(device, filename = NULL, dpi = 300) {
145145
)
146146

147147
if (is.null(device)) {
148-
device <- tolower(tools::file_ext(filename))
148+
device <- to_lower_ascii(tools::file_ext(filename))
149149
}
150150

151151
if (!is.character(device) || length(device) != 1) {

R/stat-ydensity.r

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ calc_bw <- function(x, bw) {
110110
if (length(x) < 2)
111111
stop("need at least 2 points to select a bandwidth automatically", call. = FALSE)
112112
bw <- switch(
113-
tolower(bw),
113+
to_lower_ascii(bw),
114114
nrd0 = stats::bw.nrd0(x),
115115
nrd = stats::bw.nrd(x),
116116
ucv = stats::bw.ucv(x),

R/utilities.r

+16-2
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,20 @@ has_name <- function(x) {
302302
!is.na(nms) & nms != ""
303303
}
304304

305+
# Use chartr() for safety since toupper() fails to convert i to I in Turkish locale
306+
lower_ascii <- "abcdefghijklmnopqrstuvwxyz"
307+
upper_ascii <- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
308+
to_lower_ascii <- function(x) chartr(upper_ascii, lower_ascii, x)
309+
to_upper_ascii <- function(x) chartr(lower_ascii, upper_ascii, x)
310+
311+
tolower <- function(x) {
312+
stop('Please use `to_lower_ascii()`, which works fine in all locales.', call. = FALSE)
313+
}
314+
315+
toupper <- function(x) {
316+
stop('Please use `to_upper_ascii()`, which works fine in all locales.', call. = FALSE)
317+
}
318+
305319
# Convert a snake_case string to camelCase
306320
camelize <- function(x, first = FALSE) {
307321
x <- gsub("_(.)", "\\U\\1", x, perl = TRUE)
@@ -313,11 +327,11 @@ snakeize <- function(x) {
313327
x <- gsub("([A-Za-z])([A-Z])([a-z])", "\\1_\\2\\3", x)
314328
x <- gsub(".", "_", x, fixed = TRUE)
315329
x <- gsub("([a-z])([A-Z])", "\\1_\\2", x)
316-
tolower(x)
330+
to_lower_ascii(x)
317331
}
318332

319333
firstUpper <- function(s) {
320-
paste(toupper(substring(s, 1,1)), substring(s, 2), sep = "")
334+
paste0(to_upper_ascii(substring(s, 1, 1)), substring(s, 2))
321335
}
322336

323337
snake_class <- function(x) {

0 commit comments

Comments
 (0)