{"action":"created","issue":{"url":"https://api.github.com/repos/Rdatatable/data.table/issues/1057","labels_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1057/labels{/name}","comments_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1057/comments","events_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1057/events","html_url":"https://github.com/Rdatatable/data.table/issues/1057","id":59475536,"number":1057,"title":"[request] recursion","user":{"login":"davids99us","id":5600259,"avatar_url":"https://avatars.githubusercontent.com/u/5600259?v=3","gravatar_id":"","url":"https://api.github.com/users/davids99us","html_url":"https://github.com/davids99us","followers_url":"https://api.github.com/users/davids99us/followers","following_url":"https://api.github.com/users/davids99us/following{/other_user}","gists_url":"https://api.github.com/users/davids99us/gists{/gist_id}","starred_url":"https://api.github.com/users/davids99us/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davids99us/subscriptions","organizations_url":"https://api.github.com/users/davids99us/orgs","repos_url":"https://api.github.com/users/davids99us/repos","events_url":"https://api.github.com/users/davids99us/events{/privacy}","received_events_url":"https://api.github.com/users/davids99us/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-02T12:34:08Z","updated_at":"2015-03-02T22:54:05Z","closed_at":null,"body":"```R\r\nrecursive<-function(D) {\r\n  print(nrow(D))\r\n  if (nrow(D)<3) return(D)\r\n  D[,group:=cut(test,2)]\r\n  D[,recursive(.SD),by=group]\r\n}\r\nT=data.table(test=rnorm(10))\r\nrecursive(T)\r\n\r\n> source('~/R 2/Anomaly/examples/ex5.R')\r\n[1] 10\r\n[1] 8\r\n# Error in `[.data.table`(D, , `:=`(group, cut(test, 2))) : \r\n#   .SD is locked. Using := in .SD's j is reserved for possible future use; a tortuously flexible way \r\n# to modify by group. Use := in j directly to modify by group by reference.\r\n```\r\nGreat package.  It is super solid and has changed the way I program in a week.  Shouldn't it support recursion though?  Thanks\r\n"},"comment":{"url":"https://api.github.com/repos/Rdatatable/data.table/issues/comments/76845205","html_url":"https://github.com/Rdatatable/data.table/issues/1057#issuecomment-76845205","issue_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1057","id":76845205,"user":{"login":"arunsrinivasan","id":3102045,"avatar_url":"https://avatars.githubusercontent.com/u/3102045?v=3","gravatar_id":"","url":"https://api.github.com/users/arunsrinivasan","html_url":"https://github.com/arunsrinivasan","followers_url":"https://api.github.com/users/arunsrinivasan/followers","following_url":"https://api.github.com/users/arunsrinivasan/following{/other_user}","gists_url":"https://api.github.com/users/arunsrinivasan/gists{/gist_id}","starred_url":"https://api.github.com/users/arunsrinivasan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arunsrinivasan/subscriptions","organizations_url":"https://api.github.com/users/arunsrinivasan/orgs","repos_url":"https://api.github.com/users/arunsrinivasan/repos","events_url":"https://api.github.com/users/arunsrinivasan/events{/privacy}","received_events_url":"https://api.github.com/users/arunsrinivasan/received_events","type":"User","site_admin":false},"created_at":"2015-03-02T22:54:05Z","updated_at":"2015-03-02T22:54:05Z","body":"I'm not sure what you're trying to do here, but it's not recursion that's the problem, but that you're tying to modify `.SD` by reference (using `:=`). Change `recursive(.SD)` to `recursive(copy(.SD))` and your function should run without this error. "}}