Skip to content

Remove unnecessary lock on data.table #1154

@jangorecki

Description

@jangorecki

unique(.SD) makes the lock on data.table:

library(data.table)
data.table(a=c(1,1,2))[, unique(.SD)][, b := 5]
# Error in `[.data.table`(data.table(a = c(1, 1, 2))[, unique(.SD)], , `:=`(b,  : 
#   .SD is locked. Using := in .SD's j is reserved for possible future use; a tortuously flexible way to modify by group. Use := in j directly to modify by group by reference.

While this working

data.table(a=c(1,1,2))[, unique(.SD)][, copy(.SD)][, b := 5]
#    a b
#1: 1 5
#2: 2 5

As the unique(.SD) is not a by reference operation, such := should work IMO.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions