Skip to content

Commit

Permalink
Closes #774. Fixed construction of a$b() & a[[.]]() in j.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Oct 10, 2014
1 parent d17aa96 commit 022272f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion R/data.table.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
deconstruct_and_eval = function(expr, envir = parent.frame(), enclos = parent.frame()) {
if (!mode(expr) %in% c("call", "expression", "(")) return(expr)

# Fix for #774.
# the only place where a call is of length 1, that I can think of is
# a function call with empty arguments: e.g., a[[1L]]() or a$b() or b()
# and in all these cases, we *don't* want to deconstruct and eval
# hence the "else if" statement is commented below. No existing tests
# are broken in doing so. If there are other reports, will revisit.
if (length(expr) == 1L) {
if (is.expression(expr)) return (deconstruct_and_eval(expr[[1L]]))
else if (is.call(expr[[1L]])) return (list(deconstruct_and_eval(expr[[1L]])))
# else if (is.call(expr[[1L]])) return (list(deconstruct_and_eval(expr[[1L]])))
else return(expr)
}

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
8. If `DT` contains a column `class` (happens to be a reserved attribute name in R) then `DT[class=='a']` now works again without needing `options(datatable.auto.index=FALSE)`. Thanks to sunnyghkm for reporting, [#871](https://github.com/Rdatatable/data.table/issues/871).

9. Some optimisations of `.SD` in `j` was done in 1.9.4, refer to [#735](https://github.com/Rdatatable/data.table/issues/735). Due to an oversight, j-expressions of the form c(lapply(.SD, ...), list(...)) were optimised improperly. This is now fixed. Thanks to @mmeierer for filing [#861](https://github.com/Rdatatable/data.table/issues/861).


9. `j`-expressions in `DT[, col := x$y()]` (or) `DT[, col := x[[1]]()]` are now (re)constructed properly. Thanks to @ihaddad-md for reporting. Closes [#774](https://github.com/Rdatatable/data.table/issues/774).

#### NOTES


Expand Down
5 changes: 5 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -5350,6 +5350,11 @@ test(1385.2, DT[id == id.sub], DT[1:4])
DT = data.table(class=c('a','b'), x=c(1,2))
test(1386, DT[class=='a'], DT[1])

# Fix for #774 - parsing a$b() in 'j'
DT = data.table(x=1:5, y=6:10)
ll = list(foo = function() 1L)
test(1387.1, copy(DT)[, z := ll$foo()], copy(DT)[, z:=1L])
test(1387.2, copy(DT)[, z := ll[[1L]]()], copy(DT)[, z:=1L])

##########################

Expand Down

0 comments on commit 022272f

Please sign in to comment.