Skip to content

Commit

Permalink
closes #3319 -- manually escape backslash in character by processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Chirico committed Feb 8, 2019
1 parent c5ec44f commit dc57d06
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

3. Default print output (top 5 and bottom 5 rows) when ncol>255 could display the columns in the wrong order, [#3306](https://github.com/Rdatatable/data.table/issues/3306). Thanks to Kun Ren for reporting.

4. Grouping `by = 'string_with_\\'` would fail, [#3319](https://github.com/Rdatatable/data.table/issues/3319). Thanks to @HughParsonage for reporting and @MichaelChirico for the fix.

#### NOTES

1. When upgrading to 1.12.0 some Windows users might have seen `CdllVersion not found` in some circumstances. We found a way to catch that so the [helpful message](https://twitter.com/MattDowle/status/1084528873549705217) now occurs for those upgrading from versions prior to 1.12.0 too, as well as those upgrading from 1.12.0 to a later version. See item 1 in notes section of 1.12.0 below for more background.
Expand Down
6 changes: 4 additions & 2 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,10 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) {
if (length(bysub)>1L) stop("'by' is a character vector length ",length(bysub)," but one or more items include a comma. Either pass a vector of column names (which can contain spaces, but no commas), or pass a vector length 1 containing comma separated column names. See ?data.table for other possibilities.")
bysub = strsplit(bysub,split=",")[[1L]]
}
tt = grep("^[^`]+$",bysub)
if (length(tt)) bysub[tt] = paste0("`",bysub[tt],"`")
backtick_idx = grep("^[^`]+$",bysub)
if (length(backtick_idx)) bysub[backtick_idx] = paste0("`",bysub[backtick_idx],"`")
backslash_idx = grep("\\", bysub, fixed = TRUE)
if (length(backslash_idx)) bysub[backslash_idx] = gsub('\\', '\\\\', bysub[backslash_idx], fixed = TRUE)
bysub = parse(text=paste0("list(",paste(bysub,collapse=","),")"))[[1L]]
bysubl = as.list.default(bysub)
}
Expand Down
6 changes: 6 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -13320,6 +13320,12 @@ test(1982.1, tt[1L], "")
tt = as.integer(tt[tt!=""])
test(1982.2, tt, seq_along(tt))

# parse(text = 'list(`\\phantom{.}`)') fails, #3319
library(data.table)
DT <- data.table(x = 1, y = 1:5)
setnames(DT, "x", "\\phantom{.}")
test(1983.1, DT[, .(y = mean(y)), keyby = "\\phantom{.}"],
data.table(`\\phantom{.}` = 1, y = 3, key = '\\phantom{.}'))

###################################
# Add new tests above this line #
Expand Down

0 comments on commit dc57d06

Please sign in to comment.