Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Turkish dotted and dotless i properly #3011

Merged
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -19,6 +19,8 @@

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

* ggplot2 now works in Turkish locale (@yutannihilation, #3011).

# ggplot2 3.1.0

## Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion R/fortify-multcomp.r
Expand Up @@ -46,7 +46,7 @@ fortify.glht <- function(model, data, ...) {
#' @export
fortify.confint.glht <- function(model, data, ...) {
coef <- model$confint
colnames(coef) <- tolower(colnames(coef))
colnames(coef) <- to_lower_ascii(colnames(coef))

plyr::unrowname(base::data.frame(
lhs = rownames(coef),
Expand Down
2 changes: 1 addition & 1 deletion R/layer.r
Expand Up @@ -341,7 +341,7 @@ is.layer <- function(x) inherits(x, "Layer")


check_subclass <- function(x, subclass,
argname = tolower(subclass),
argname = to_lower_ascii(subclass),
env = parent.frame()) {
if (inherits(x, subclass)) {
x
Expand Down
2 changes: 1 addition & 1 deletion R/save.r
Expand Up @@ -145,7 +145,7 @@ plot_dev <- function(device, filename = NULL, dpi = 300) {
)

if (is.null(device)) {
device <- tolower(tools::file_ext(filename))
device <- to_lower_ascii(tools::file_ext(filename))
}

if (!is.character(device) || length(device) != 1) {
Expand Down
2 changes: 1 addition & 1 deletion R/stat-ydensity.r
Expand Up @@ -110,7 +110,7 @@ calc_bw <- function(x, bw) {
if (length(x) < 2)
stop("need at least 2 points to select a bandwidth automatically", call. = FALSE)
bw <- switch(
tolower(bw),
to_lower_ascii(bw),
nrd0 = stats::bw.nrd0(x),
nrd = stats::bw.nrd(x),
ucv = stats::bw.ucv(x),
Expand Down
18 changes: 16 additions & 2 deletions R/utilities.r
Expand Up @@ -302,6 +302,20 @@ has_name <- function(x) {
!is.na(nms) & nms != ""
}

# Use chartr() for safety since toupper() fails to convert i to I in Turkish locale
lower_ascii <- "abcdefghijklmnopqrstuvwxyz"
upper_ascii <- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
to_lower_ascii <- function(x) chartr(upper_ascii, lower_ascii, x)
to_upper_ascii <- function(x) chartr(lower_ascii, upper_ascii, x)

tolower <- function(x) {
stop('Please use `to_lower_ascii()`, which works fine in all locales.', call. = FALSE)
}

toupper <- function(x) {
stop('Please use `to_upper_ascii()`, which works fine in all locales.', call. = FALSE)
}

# Convert a snake_case string to camelCase
camelize <- function(x, first = FALSE) {
x <- gsub("_(.)", "\\U\\1", x, perl = TRUE)
Expand All @@ -313,11 +327,11 @@ snakeize <- function(x) {
x <- gsub("([A-Za-z])([A-Z])([a-z])", "\\1_\\2\\3", x)
x <- gsub(".", "_", x, fixed = TRUE)
x <- gsub("([a-z])([A-Z])", "\\1_\\2", x)
tolower(x)
to_lower_ascii(x)
}

firstUpper <- function(s) {
paste(toupper(substring(s, 1,1)), substring(s, 2), sep = "")
paste0(to_upper_ascii(substring(s, 1, 1)), substring(s, 2))
}

snake_class <- function(x) {
Expand Down