Data.table: setDT should be more careful on altering its input

Created on 17 Mar 2018  路  2Comments  路  Source: Rdatatable/data.table

setDT remove names attribute from input vector, that should not happen.

x = c(a = 4, b = 5)
setDT(list(c = x))[]
names(x) 

Related

4240

https://github.com/Rdatatable/data.table/issues/2487
https://github.com/Rdatatable/data.table/issues/1916
https://github.com/Rdatatable/data.table/issues/1244
https://github.com/Rdatatable/data.table/issues/683

High bug

All 2 comments

A related bug:

setDT even modifies the input vector if the data.table is modified later on

see here

a <- 1:2 / 2
x <- 1:10 / 2
y <- 11/2
dt <- data.frame(a, x, y)
setDT(dt)
dt[ , cond := a == 1]
dt[(cond), c("x", "y") := list(y, x)]
x
#[1] 0.5 5.5 1.5 5.5 2.5 5.5 3.5 5.5 4.5 5.5

@BenoitLondon your issue is slightly different.. I've answered your SO post.

Was this page helpful?
0 / 5 - 0 ratings