{"action":"created","issue":{"url":"https://api.github.com/repos/Rdatatable/data.table/issues/1362","labels_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1362/labels{/name}","comments_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1362/comments","events_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1362/events","html_url":"https://github.com/Rdatatable/data.table/issues/1362","id":108400725,"number":1362,"title":"dataset's local scoping for `set` function - `value` argument","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":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-25T20:18:03Z","updated_at":"2015-09-25T23:12:36Z","closed_at":"2015-09-25T23:12:36Z","body":"Feature request.\r\nI would like to avoid `[.data.table` overhead when using `:=` in loop for adding new computed column. The `value` argument in `set` function has scope of local frame, not the dataset. \r\nThe most basic example, adding new `cc` column based on `aa` and `bb`:\r\n```r\r\nlibrary(data.table)\r\ndt = data.table(aa = 1, bb = 2)\r\nset(dt, j = \"cc\", value = aa + bb)\r\n# Error in set(dt, j = \"cc\", value = aa + bb) : object 'aa' not found\r\n```\r\n\r\nActual real case usage, compute a list of indicators on the dataset by providing list of calls:\r\n```r\r\nlibrary(data.table)\r\ndt = data.table(aa = 1, bb = 2)\r\ncompute_indicator = function(data, indicator){\r\n    indicator = substitute(indicator)\r\n    stopifnot(is.language(indicator), indicator[[1L]]==quote(list))\r\n    indicator = as.list(indicator[-1L])\r\n    lapply(names(indicator), function(name) data[, (name) := eval(indicator[[name]])])\r\n    data\r\n}\r\ncompute_indicator(\r\n    data = dt,\r\n    indicator = list(\r\n        sum_aa_bb = aa + bb,\r\n        aa_div_2 = aa / 2,\r\n        ratio = sum_aa_bb / aa_div_2\r\n    )\r\n)\r\nprint(dt)\r\n#    aa bb sum_aa_bb aa_div_2 ratio\r\n# 1:  1  2         3      0.5     6\r\n```"},"comment":{"url":"https://api.github.com/repos/Rdatatable/data.table/issues/comments/143373478","html_url":"https://github.com/Rdatatable/data.table/issues/1362#issuecomment-143373478","issue_url":"https://api.github.com/repos/Rdatatable/data.table/issues/1362","id":143373478,"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},"created_at":"2015-09-25T23:12:36Z","updated_at":"2015-09-25T23:12:36Z","body":"I've just rethink that FR. It seems to have impact not big enough here. There will be no more than 50/100 indicators, and `[.data.table` will be relatively cheap comparing to `RHS` evaluation - the bottleneck."}}