Skip to content

setnames() should not exit early if colnames encodings are different #3845

Closed

Description

@shrektan

This issue is introducied by #3784

As a Chinese user working mostly on Windows, I need to pay attention to encodings carefully. Usually I need to convert the native encoded non-ASCII colnames to UTF-8 encoded in order to gain cross-platform compatibilities (I need to run some code on a docker based machine so cross-platform compatible is important).

So it's important for me to reset the equal colnames if the old and new are encoded differently. But now I can't do that anymore.

library(data.table)
snative <- c('中文', '汉字')
sutf8 <- enc2utf8(snative)
dt <- data.table(a = 1, b = 2)
setnames(dt, snative)
Encoding(colnames(dt))
#> [1] "unknown" "unknown"
setnames(dt, sutf8)
Encoding(colnames(dt))
#> [1] "unknown" "unknown"

Created on 2019-09-09 by the reprex package (v0.2.1)

Session info
devtools::session_info()
#> - Session info ----------------------------------------------------------
#>  setting  value                                              
#>  version  R version 3.4.4 (2018-03-15)                       
#>  os       Windows 7 x64 SP 1                                 
#>  system   x86_64, mingw32                                    
#>  ui       RTerm                                              
#>  language (EN)                                               
#>  collate  Chinese (Simplified)_People's Republic of China.936
#>  ctype    Chinese (Simplified)_People's Republic of China.936
#>  tz       Asia/Taipei                                        
#>  date     2019-09-09                                         
#> 
#> - Packages --------------------------------------------------------------
#>  package     * version    date       lib source        
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.4.4)
#>  backports     1.1.3      2018-12-14 [1] CRAN (R 3.4.4)
#>  callr         3.2.0      2019-03-15 [1] CRAN (R 3.4.4)
#>  cli           1.1.0      2019-03-19 [1] CRAN (R 3.4.4)
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.4.4)
#>  data.table  * 1.12.3     2019-09-09 [1] local         
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.4.4)
#>  devtools      2.0.1      2018-10-26 [1] CRAN (R 3.4.4)
#>  digest        0.6.18     2018-10-10 [1] CRAN (R 3.4.4)
#>  evaluate      0.13       2019-02-12 [1] CRAN (R 3.4.4)
#>  fs            1.2.7      2019-03-19 [1] CRAN (R 3.4.4)
#>  glue          1.3.1      2019-03-12 [1] CRAN (R 3.4.4)
#>  highr         0.8        2019-03-20 [1] CRAN (R 3.4.4)
#>  htmltools     0.3.6.9000 2018-05-07 [1] local         
#>  knitr         1.22       2019-03-08 [1] CRAN (R 3.4.4)
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.4.4)
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.4.4)
#>  pkgbuild      1.0.3      2019-03-20 [1] CRAN (R 3.4.4)
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.4.4)
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.4.1)
#>  processx      3.3.0      2019-03-10 [1] CRAN (R 3.4.4)
#>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.4.4)
#>  R6            2.4.0      2019-02-14 [1] CRAN (R 3.4.4)
#>  Rcpp          1.0.1      2019-03-17 [1] CRAN (R 3.4.4)
#>  remotes       2.0.2      2018-10-30 [1] CRAN (R 3.4.4)
#>  rlang         0.3.3      2019-03-29 [1] CRAN (R 3.4.4)
#>  rmarkdown     1.12       2019-03-14 [1] CRAN (R 3.4.4)
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.4.3)
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.4.4)
#>  stringi       1.4.3      2019-03-12 [1] CRAN (R 3.4.4)
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.4.4)
#>  testthat      2.1.1.9000 2019-06-22 [1] local         
#>  usethis       1.4.0      2018-08-14 [1] CRAN (R 3.4.4)
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.4.4)
#>  xfun          0.6        2019-04-02 [1] CRAN (R 3.4.4)
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.4.4)
#> 
#> [1] D:/app/R_lib/3.1
#> [2] D:/app/R/library
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugdevencoding

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions