{"action":"created","issue":{"url":"https://api.github.com/repos/Rdatatable/data.table/issues/1247","labels_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1247/labels{/name}","comments_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1247/comments","events_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1247/events","html_url":"https://github.com/Rdatatable/data.table/issues/1247","id":97834760,"number":1247,"title":"Inconsistent assignment behavior","user":{"login":"renkun-ken","id":4662568,"avatar_url":"https://avatars.githubusercontent.com/u/4662568?v=3","gravatar_id":"","url":"https://api.github.com/users/renkun-ken","html_url":"https://github.com/renkun-ken","followers_url":"https://api.github.com/users/renkun-ken/followers","following_url":"https://api.github.com/users/renkun-ken/following{/other_user}","gists_url":"https://api.github.com/users/renkun-ken/gists{/gist_id}","starred_url":"https://api.github.com/users/renkun-ken/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/renkun-ken/subscriptions","organizations_url":"https://api.github.com/users/renkun-ken/orgs","repos_url":"https://api.github.com/users/renkun-ken/repos","events_url":"https://api.github.com/users/renkun-ken/events{/privacy}","received_events_url":"https://api.github.com/users/renkun-ken/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-29T01:24:38Z","updated_at":"2015-07-29T02:13:02Z","closed_at":null,"body":"The following behavior seems inconsistent:\r\n\r\n```rconsole\r\n> p <- data.table(a=1:10)\r\n> x <- 0\r\n> p[, { cat(x, \",\", a, \"\\n\"); x <<- a; NULL}, by = a]\r\n0 , 1 \r\n2 , 2  # why not 1 , 2 ?\r\n3 , 3 \r\n4 , 4 \r\n5 , 5 \r\n6 , 6 \r\n7 , 7 \r\n8 , 8 \r\n9 , 9 \r\n10 , 10 \r\nEmpty data.table (0 rows) of 1 col: a\r\n```\r\n\r\nwhich gives different output from `for`\r\n\r\n```rsoncole\r\n> x <- 0\r\n> for (m in p$a) { cat(x, \",\", m, \"\\n\"); x <<- m; }\r\n0 , 1 \r\n1 , 2 \r\n2 , 3 \r\n3 , 4 \r\n4 , 5 \r\n5 , 6 \r\n6 , 7 \r\n7 , 8 \r\n8 , 9 \r\n9 , 10 \r\n```\r\n\r\nI'm using latest dev of data.table. My session info:\r\n\r\n```\r\nR version 3.2.1 (2015-06-18)\r\nPlatform: x86_64-w64-mingw32/x64 (64-bit)\r\nRunning under: Windows 8 x64 (build 9200)\r\n\r\nlocale:\r\n[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   \r\n[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          \r\n[5] LC_TIME=English_United States.1252    \r\n\r\nattached base packages:\r\n[1] stats     graphics  grDevices utils     datasets  methods   base     \r\n\r\nother attached packages:\r\n[1] data.table_1.9.5\r\n\r\nloaded via a namespace (and not attached):\r\n[1] tools_3.2.1  chron_2.3-47\r\n```"},"comment":{"url":"https://api.github.com/repos/Rdatatable/data.table/issues/comments/125807490","html_url":"https://github.com/Rdatatable/data.table/issues/1247#issuecomment-125807490","issue_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1247","id":125807490,"user":{"login":"renkun-ken","id":4662568,"avatar_url":"https://avatars.githubusercontent.com/u/4662568?v=3","gravatar_id":"","url":"https://api.github.com/users/renkun-ken","html_url":"https://github.com/renkun-ken","followers_url":"https://api.github.com/users/renkun-ken/followers","following_url":"https://api.github.com/users/renkun-ken/following{/other_user}","gists_url":"https://api.github.com/users/renkun-ken/gists{/gist_id}","starred_url":"https://api.github.com/users/renkun-ken/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/renkun-ken/subscriptions","organizations_url":"https://api.github.com/users/renkun-ken/orgs","repos_url":"https://api.github.com/users/renkun-ken/repos","events_url":"https://api.github.com/users/renkun-ken/events{/privacy}","received_events_url":"https://api.github.com/users/renkun-ken/received_events","type":"User","site_admin":false},"created_at":"2015-07-29T02:13:02Z","updated_at":"2015-07-29T02:13:02Z","body":"@shrektan I think you are right. `<<-` in `j` performs reference assignment. The following code show this explicitly:\r\n\r\n```rconsole\r\n> x <- 0\r\n> p[, { x <<- a; NULL }]\r\nNULL\r\n> x\r\n [1]  1  2  3  4  5  6  7  8  9 10\r\n> p[a <= 5, a := 0]\r\n> x\r\n [1]  0  0  0  0  0  6  7  8  9 10\r\n```\r\n\r\n@franknarf1, indeed, this is more like an experiment on how things work than a practical way of use :)"}}