Skip to content

setnames() can't set dt with non-ascii names #3844

Closed

Description

@shrektan

(It only occurs on the latest dev version of data.table)

The issue is introduced by #3784 . The cause is chmatchdup() is somehow can't handle non-ASCII strings correctly.

Note, it should be Windows-speicific.

library(data.table)

nonascii <- c('中', '文')
data.table:::chmatchdup(
  c(nonascii, nonascii), nonascii
)
#> [1] 1 2 1 2

ascii <- c('a', 'b')
data.table:::chmatchdup(
  c(ascii, ascii), ascii
)
#> [1]  1  2 NA NA

dt <- data.table("中文" = 1, "汉字" = 2)
setnames(dt, colnames(dt), colnames(dt))
#> Error in setnames(dt, colnames(dt), colnames(dt)): Some items of 'old' are duplicated (ambiguous) in column names: [中文, 汉字]

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

Activity

  1. added this to the 1.12.4 milestone on Sep 9, 2019
  2. self-assigned this
    on Sep 9, 2019
  3. shrektan commented on Sep 9, 2019

    @shrektan
    MemberAuthor

    @MichaelChirico I don't know why you choose to use chmatchdup() in #3784. This function doesn't support non-ASCII strings (specifically speaking, for any Encoding-marked strings, it falls to match(), which behaves differently and won't set duplicates as NA).

    return (chin ? match_logical(table, x) : match(table, x, nomatch));

    Reproducible code on macOS

    library(data.table)
    utf8 = c("\u00e7ile", "\u00de")
    latin1 = iconv(utf8, from = "UTF-8", to = "latin1")
    data.table:::chmatchdup(c(utf8, utf8), latin1)
    data.table:::chmatchdup(c('a', 'b', 'a', 'b'), c('a', 'b'))

    UPDATE: never mind, it should have been fixed now.

  4. added
    encoding
    on Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugencoding

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions