{"action":"opened","issue":{"url":"https://api.github.com/repos/Rdatatable/data.table/issues/1154","labels_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1154/labels{/name}","comments_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1154/comments","events_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1154/events","html_url":"https://github.com/Rdatatable/data.table/issues/1154","id":78283192,"number":1154,"title":"Remove unnecessary lock on data.table","user":{"login":"jangorecki","id":3627377,"avatar_url":"https://avatars.githubusercontent.com/u/3627377?v=3","gravatar_id":"","url":"https://api.github.com/users/jangorecki","html_url":"https://github.com/jangorecki","followers_url":"https://api.github.com/users/jangorecki/followers","following_url":"https://api.github.com/users/jangorecki/following{/other_user}","gists_url":"https://api.github.com/users/jangorecki/gists{/gist_id}","starred_url":"https://api.github.com/users/jangorecki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jangorecki/subscriptions","organizations_url":"https://api.github.com/users/jangorecki/orgs","repos_url":"https://api.github.com/users/jangorecki/repos","events_url":"https://api.github.com/users/jangorecki/events{/privacy}","received_events_url":"https://api.github.com/users/jangorecki/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-05-19T22:55:01Z","updated_at":"2015-05-19T22:55:01Z","closed_at":null,"body":"`unique(.SD)` makes the lock on data.table:\r\n```r\r\nlibrary(data.table)\r\ndata.table(a=c(1,1,2))[, unique(.SD)][, b := 5]\r\n# Error in `[.data.table`(data.table(a = c(1, 1, 2))[, unique(.SD)], , `:=`(b,  : \r\n#   .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.\r\n```\r\nWhile this working\r\n```r\r\ndata.table(a=c(1,1,2))[, unique(.SD)][, copy(.SD)][, b := 5]\r\n#    a b\r\n# 1: 1 5\r\n# 2: 2 5\r\n```\r\n\r\nAs the `unique(.SD)` is not a *by reference* operation, such `:=` should work IMO."}}