Skip to content

Why does expr_text() behave differently for variables containing non-ASCII characters? #691

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

Closed
yutannihilation opened this issue Nov 27, 2018 · 5 comments

Comments

@yutannihilation
Copy link
Contributor

(original issue: tidyverse/ggplot2#3017)

If the expression is a symbol and it has any non-ASCII characters, expr_text() adds backticks except when the character is at the head of the variable name. I'm failing to see the rule behind this... Is this intended? I feel backticks should not be added at all as long as the characters are representable in the current locale.

library(rlang)

expr_text(sym("áa"))
#> [1] "áa"
expr_text(sym(""))
#> [1] "`aá`"
as_string(sym(""))
#> [1] "aá"

aá <- 1
aá
#> [1] 1

Created on 2018-11-27 by the reprex package (v0.2.1)

Session info
devtools::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.5.1 (2018-07-02)
#>  os       macOS High Sierra 10.13.6   
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language en                          
#>  collate  ja_JP.UTF-8                 
#>  ctype    ja_JP.UTF-8                 
#>  tz       Asia/Tokyo                  
#>  date     2018-11-27                  
#> 
#> ─ Packages ──────────────────────────────────────────────────────────────
#>  package     * version    date       lib source                      
#>  assertthat    0.2.0      2017-04-11 [1] CRAN (R 3.5.0)              
#>  backports     1.1.2      2017-12-13 [1] CRAN (R 3.5.0)              
#>  base64enc     0.1-3      2015-07-28 [1] CRAN (R 3.5.0)              
#>  callr         3.0.0      2018-08-24 [1] CRAN (R 3.5.0)              
#>  cli           1.0.1      2018-09-25 [1] CRAN (R 3.5.0)              
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.5.0)              
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.5.0)              
#>  devtools      2.0.1      2018-10-26 [1] CRAN (R 3.5.1)              
#>  digest        0.6.18     2018-10-10 [1] CRAN (R 3.5.1)              
#>  evaluate      0.12       2018-10-09 [1] CRAN (R 3.5.0)              
#>  fs            1.2.6      2018-08-23 [1] CRAN (R 3.5.0)              
#>  glue          1.3.0      2018-07-17 [1] CRAN (R 3.5.1)              
#>  highr         0.7        2018-06-09 [1] CRAN (R 3.5.0)              
#>  htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.5.0)              
#>  knitr         1.20.22    2018-11-26 [1] local                       
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.5.0)              
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.5.0)              
#>  pkgbuild      1.0.2      2018-10-16 [1] CRAN (R 3.5.0)              
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.5.0)              
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.5.0)              
#>  processx      3.2.0      2018-08-16 [1] CRAN (R 3.5.0)              
#>  ps            1.2.1      2018-11-06 [1] CRAN (R 3.5.1)              
#>  R6            2.3.0      2018-10-04 [1] CRAN (R 3.5.0)              
#>  Rcpp          1.0.0      2018-11-07 [1] CRAN (R 3.5.1)              
#>  remotes       2.0.2      2018-10-30 [1] CRAN (R 3.5.0)              
#>  rlang       * 0.3.0.9000 2018-11-27 [1] local                       
#>  rmarkdown     1.10       2018-06-11 [1] CRAN (R 3.5.0)              
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.5.0)              
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.5.1)              
#>  stringi       1.2.4      2018-07-20 [1] CRAN (R 3.5.0)              
#>  stringr       1.3.1      2018-05-10 [1] CRAN (R 3.5.0)              
#>  testthat      2.0.1      2018-10-13 [1] CRAN (R 3.5.0)              
#>  usethis       1.4.0      2018-08-14 [1] CRAN (R 3.5.0)              
#>  withr         2.1.2.9000 2018-10-25 [1] Github (r-lib/withr@be57595)
#>  xfun          0.4        2018-10-23 [1] CRAN (R 3.5.1)              
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.5.0)              
#> 
#> [1] /Library/Frameworks/R.framework/Versions/3.5/Resources/library
@yutannihilation yutannihilation changed the title Why expr_text() behaves differently for variables containing non-ASCII characters? Why does expr_text() behave differently for variables containing non-ASCII characters? Nov 27, 2018
lionel- added a commit that referenced this issue Dec 10, 2018
@lionel-
Copy link
Member

lionel- commented Dec 13, 2018

Hello Hiroaki, could you install dev rlang and take this for a spin please? I'd like to make a quick patch release soon. I have run R CMD check for dplyr on Windows and found no issues so hopefully it doesn't break anything for non-unicode locales.

@yutannihilation
Copy link
Contributor Author

Sure, I'll do it later today or tomorrow.

@yutannihilation
Copy link
Contributor Author

Confirmed this issue is fixed on Windows. Thanks!

library(rlang)

expr_text(sym("あa"))
#> [1] "あa"
expr_text(sym("aあ"))
#> [1] "aあ"

Created on 2018-12-13 by the reprex package (v0.2.1)

(By the way, I remembered I reported this issue from macOS; On Windows in my locale á is transliterated into a, so I would never see this problem...)

@lionel-
Copy link
Member

lionel- commented Dec 13, 2018

Thanks! Please also let me know if you see anything weird while working with dplyr/ggplot2.

@yutannihilation
Copy link
Contributor Author

Sure 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants