Skip to content

Commit

Permalink
Closes #3507 -- empty argument in j output caught early & stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Chirico committed Apr 16, 2019
1 parent 6f53b27 commit 8305d14
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -41,6 +41,8 @@

2. `keyby=colName` could use the wrong index and return incorrect results if both `colName` and `colNameExtra` (where `colName` is a leading subset of characters of `colNameExtra`) are column names and an index exists on `colNameExtra`, [#3498](https://github.com/Rdatatable/data.table/issues/3498). Thanks to Xianying Tan for the detailed report and pinpointing the source line at fault.

3. `j = list(x, )` would sometimes correctly error but with a confusing diagnosis, [#3507](https://github.com/Rdatatable/data.table/issues/3507). This is now caught and stopped much earlier with a helpful admonition; thanks @eddelbuettel for the report.

#### NOTES

1. `rbindlist`'s `use.names="check"` now emits its message for automatic column names (`"V[0-9]+"`) too, [#3484](https://github.com/Rdatatable/data.table/pull/3484). See news item 5 of v1.12.2 below.
Expand Down
8 changes: 6 additions & 2 deletions R/data.table.R
Expand Up @@ -982,8 +982,12 @@ replace_dot_alias <- function(e) {
jvnames = names(jsubl)[-1L] # check list(a=sum(v),v)
if (is.null(jvnames)) jvnames = rep.int("", length(jsubl)-1L)
for (jj in seq.int(2L,length(jsubl))) {
if (jvnames[jj-1L] == "" && mode(jsubl[[jj]])=="name")
jvnames[jj-1L] = gsub("^[.](N|I|GRP|BY)$","\\1",deparse(jsubl[[jj]]))
if (jvnames[jj-1L] == "" && mode(jsubl[[jj]])=="name") {
# #3507 -- list(x, ) caught here as an error
if (!nzchar(as.character(jsubl[[jj]])))
stop("Empty list argument at input ", jj - 1L, "; please explicitly provide 'NULL' if you're intending to drop a column, and note that R doesn't currently support trailing commas.")
jvnames[jj-1L] = gsub("^[.](N|I|GRP|BY)$", "\\1", deparse(jsubl[[jj]]))
}
# TO DO: if call to a[1] for example, then call it 'a' too
}
setattr(jsubl, "names", NULL) # drops the names from the list so it's faster to eval the j for each group. We'll put them back aftwards on the result.
Expand Down
6 changes: 6 additions & 0 deletions inst/tests/tests.Rraw
Expand Up @@ -14045,6 +14045,12 @@ DT[2,t:= as.POSIXct("2019-01-01 19:00:01",tz = "UTC")]
test(2026.3, capture.output(print(DT)), c(" v1 t","1: 1 <NA>", "2: NA 2019-01-01 19:00:01"))
test(2026.4, capture.output(print(DT, timezone = TRUE)), c(" v1 t","1: 1 <NA>","2: NA 2019-01-01 19:00:01 UTC"))

# 3507 -- catching list(x, ) errors gracefully
DT = data.table(a = 1:5)
## original error triggered with grouping
test(2027.1, DT[ , list(1, ), by = a], error = 'Empty list argument at input 2')
## consistency in error in non-grouping query
test(2027.2, DT[ , list(1, )], error = 'Empty list argument at input 2')

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

0 comments on commit 8305d14

Please sign in to comment.