Skip to content
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

Remove unnecessary lock on data.table #1154

Closed
jangorecki opened this issue May 19, 2015 · 1 comment
Closed

Remove unnecessary lock on data.table #1154

jangorecki opened this issue May 19, 2015 · 1 comment
Assignees
Labels
Milestone

Comments

@jangorecki
Copy link
Member

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.

@franknarf1
Copy link
Contributor

Not sure if this is any less wasteful than a copy, but c(unique(.SD)) is unlocked:

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

@arunsrinivasan arunsrinivasan added this to the v1.9.6 milestone May 28, 2015
@arunsrinivasan arunsrinivasan self-assigned this May 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants