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
Mutate returns nothing from data tables #1431
Comments
Found out from See the referenced |
I think this should be straightforward to fix. Minimal reprex: library(data.table)
library(dplyr)
mutate(data.table(x = 1), y = 2) |
Note that it's only the first time displaying the Example console output: > library(data.table)
> library(dplyr)
> foo <- mutate(data.table(x = 1), y = 2)
> foo
> foo
x y
1: 1 2 For others waiting for this to be fixed: if wanting to see the output from a mutate call, e.g. when doing exploratory analysis, calling > library(data.table)
> library(dplyr)
> mutate(data.table(x = 1), y = 2)
> .Last.value
x y
1: 1 2 |
I think it is more than just a display problem. library(data.table)
DT <- data.table(x = 1)
DT
#> x
#>1: 1
address(DT)
#> [1] "0x5e67190"
DT[, y := 2] # Display nothing but y is added in DT
DT
#> x y
#>1: 1 2
address(DT) # And it is modified by reference (same address)
#> [1] "0x5e67190" When you add a column in data.table with mutate, it displays nothing and it modifies nothing. library(data.table)
library(dplyr)
DT <- data.table(x = 1)
DT
#> x
#>1: 1
mutate(DT, y = 2) # Displays nothing
DT
#> x
#>1: 1 Yet, the result has the correct class class(mutate(DT, y = 2))
#>[1] "data.table" "data.frame" And if we force evalutation the data.table way with mutate(DT, y = 2)[]
#> x y
#>1: 1 2
DT
#> x
#>1: 1 If we assign, the results is correct but it is indeed a new object DT <- data.table(x = 1)
DT
#> x
#>1: 1
address(DT)
#>[1] "0x5e20600"
DT <- mutate(DT, y = 2)
DT # displays nothing - see data.table bug fix
DT # displays results
#> x y
#>1: 1 2
address(DT) # new object so new address
[1] "0x3f9bf40" Behavior is different when manipulation data.table objects with dplyr package. or data.table package. (related with #614 ?) Perhaps, it is intentional because modification by reference in data.table is not the way of things for dplyr. In that case, I missed that... It is still disturbing when you are used to work with data.table and dplyr to take advantage of both package. |
This has not yet been resolved, issue has moved to dtplyr (data.table backend of dplyr) issues: tidyverse/dtplyr#11 |
When I pipe a
data.table
intomutate
, it returns nothing and breaks the rest of the chain.I just observed this morning for the first time and I'm afraid I'm at a loss to pinpoint the specific change that caused it. I'm inclined to believe it was the
data.table
update to 1.9.6 that happened Sept 19, but I can't be sure.On a fresh Docker image of rocker/ropensci, with
data.table
v1.9.6 anddplyr
v0.4.3, the following is reproducible:The text was updated successfully, but these errors were encountered: