You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Transformation/assignment through := lapply(.SD, ...) can switch column names #4874
When using := lapply(.SD, ...) to transform columns in place, if .SDcols contains duplicates and assignment is done by groups, then column names can be switched.
dt = data.table(
group = c(rep('group1',5),rep('group2',5)),
x = as.numeric(c(1:5, 1:5)),
y = as.numeric(c(5:1, 5:1)),
z = as.numeric(c(1,2,3,2,1, 1,2,3,2,1))
)
cols = c('y','x','y','z') # contains a duplicate column name
dt[,(cols) := lapply(.SD,identity), .SDcols=cols] # Error (OK)
dt[,(cols) := lapply(.SD,identity), .SDcols=cols, by=group] # No error! Columns 'y' and 'z' are now switched
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 14393)
changed the title [-]Transformation/assignment through `:= lapply(.SD, ...)` can switch column names[/-][+]Transformation/assignment through := lapply(.SD, ...) can switch column names[/+]on Jan 14, 2021
Activity
[-]Transformation/assignment through `:= lapply(.SD, ...)` can switch column names[/-][+]Transformation/assignment through := lapply(.SD, ...) can switch column names[/+]ben-schwen commentedon Jan 20, 2021
Hi,
could you also add information about which version of
data.tableyou are using? I can't reproduce it with1.3.6and Windows 10 or Debian.joesnacks commentedon Jan 20, 2021
Here's the full output of sessionInfo():
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 14393)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices datasets utils methods base
other attached packages:
[1] data.table_1.12.2
loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0
======================
I have also been able to replicate it on another machine with a slightly different configuration:
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices datasets utils methods base
other attached packages:
[1] data.table_1.12.0
loaded via a namespace (and not attached):
[1] compiler_3.5.2 tools_3.5.2 yaml_2.2.0
ben-schwen commentedon Jan 20, 2021
It seems that this behavior was fixed with #3771. Hence, any version >=
1.12.4should work.jangorecki commentedon Jan 20, 2021
Thanks @ben-schwen to taking care of this issue! @joesnacks could you please upgrade your package to ensure issue is resolved for you?
joesnacks commentedon Jan 20, 2021
Thanks! I upgraded to version 1.12.8 and can confirm that the issue is fixed.