This is probabily related to Bug
[#2223] Deleting multiple columns out-of-order using := causes seg fault
However, using `:=` with `with = F` does not appear to work as intended.
DT <- data.table(c1 = 1:2)
DT[, `:=`(c("c2", "c1"), list(c1 * 10, NULL)), with = FALSE]
## Warning: Adding new column 'c2' then assigning NULL (deleting it).
## c1
## 1: 10
## 2: 20
The new column should be called `c2` and it be the only column in DT.
The following gives an appropriate warning (and result)
DT <- data.table(c1 = 1:2)
DT[, `:=`(c("c1", "c2"), list(c1 * 10, NULL)), with = FALSE]
## Warning: Adding new column 'c2' then assigning NULL (deleting it).
## c1
## 1: 10
## 2: 20
Obviously this is a non-standard (and non-reccomended) approach. The following
would be considered more *standard*
DT <- data.table(c1 = 1:2)
# save as a new data.table
DT2 <- DT[, list(c2 = 10 * c1)]
# use setnames
DT <- data.table(c1 = 1:2)
setnames(DT[, `:=`(c1, 10 * c1)], "c1", "c2")
Regards,
Michael
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help