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

Unrecognized escaped in keyby #3319

Closed
HughParsonage opened this issue Jan 26, 2019 · 4 comments · Fixed by #3375
Closed

Unrecognized escaped in keyby #3319

HughParsonage opened this issue Jan 26, 2019 · 4 comments · Fixed by #3375
Milestone

Comments

@HughParsonage
Copy link
Member

library(data.table)
DT <- data.table(x = 1, y = 1:5)
setnames(DT, "x", "\\phantom{.}")
DT[, .(y = mean(y)), keyby = "\\phantom{.}"]
#> Error: '\p' is an unrecognized escape in character string starting "`\p"

Of course, I can change to keyby = `\\phantom{.}` , but that can be hard to know in advance.

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

Session info
devtools::session_info()
#> - Session info ----------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.2 (2018-12-20)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_Australia.1252      
#>  ctype    English_Australia.1252      
#>  tz       Australia/Sydney            
#>  date     2019-01-27                  
#> 
#> - Packages --------------------------------------------------------------
#>  package     * version date       lib source        
#>  assertthat    0.2.0   2017-04-11 [1] CRAN (R 3.5.1)
#>  backports     1.1.3   2018-12-14 [1] CRAN (R 3.5.2)
#>  callr         3.1.1   2018-12-21 [1] CRAN (R 3.5.2)
#>  cli           1.0.1   2018-09-25 [1] CRAN (R 3.5.1)
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 3.5.1)
#>  data.table  * 1.12.0  2019-01-13 [1] CRAN (R 3.5.2)
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 3.5.1)
#>  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.1)
#>  fs            1.2.6   2018-08-23 [1] CRAN (R 3.5.1)
#>  glue          1.3.0   2018-07-17 [1] CRAN (R 3.5.1)
#>  highr         0.7     2018-06-09 [1] CRAN (R 3.5.1)
#>  htmltools     0.3.6   2017-04-28 [1] CRAN (R 3.5.1)
#>  knitr         1.21    2018-12-10 [1] CRAN (R 3.5.2)
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 3.5.1)
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 3.5.1)
#>  pkgbuild      1.0.2   2018-10-16 [1] CRAN (R 3.5.1)
#>  pkgload       1.0.2   2018-10-29 [1] CRAN (R 3.5.1)
#>  prettyunits   1.0.2   2015-07-13 [1] CRAN (R 3.5.1)
#>  processx      3.2.1   2018-12-05 [1] CRAN (R 3.5.1)
#>  ps            1.3.0   2018-12-21 [1] CRAN (R 3.5.2)
#>  R6            2.3.0   2018-10-04 [1] CRAN (R 3.5.1)
#>  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.1)
#>  rlang         0.3.0.1 2018-10-25 [1] CRAN (R 3.5.1)
#>  rmarkdown     1.11    2018-12-08 [1] CRAN (R 3.5.2)
#>  rprojroot     1.3-2   2018-01-03 [1] CRAN (R 3.5.1)
#>  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.1)
#>  stringr       1.3.1   2018-05-10 [1] CRAN (R 3.5.1)
#>  testthat      2.0.1   2018-10-13 [1] CRAN (R 3.5.1)
#>  usethis       1.4.0   2018-08-14 [1] CRAN (R 3.5.1)
#>  withr         2.1.2   2018-03-15 [1] CRAN (R 3.5.1)
#>  xfun          0.4     2018-10-23 [1] CRAN (R 3.5.1)
#>  yaml          2.2.0   2018-07-25 [1] CRAN (R 3.5.1)
#> 
#> [1] C:/R/R-3.5.2/library
#> [2] C:/R/R-3.5.1/library
@HughParsonage HughParsonage changed the title Unrecognized escaped Unrecognized escaped in keyby Jan 26, 2019
@jangorecki
Copy link
Member

jangorecki commented Jan 27, 2019

Instead of dealing with that particular I would prefer to provide a helper function for cleaning up column names, and ask people to use that in such cases.

@DavidArenburg
Copy link
Member

We could add check.names argument to setnames (like we have in setDT or fread)

@sritchie73
Copy link
Contributor

sritchie73 commented Jan 31, 2019

The "\" character is always treated as an escape key (using the following character) in strings (even when writing markdown comments here!). So if you want an actual backslash, you need to escape each backslash:

> DT[, .(y = mean(y)), keyby = "\\\\phantom{.}"]
   \\phantom{.} y
1:            1 3

@HughParsonage
Copy link
Member Author

@sritchie73 That's not quite true.

DT <- data.table(x = 1)
setnames(DT, "\n")
DT[, .(a = 1), keyby = "\n"]
#    \n a
# 1:  1 1

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

Successfully merging a pull request may close this issue.

5 participants