{"action":"created","issue":{"url":"https://api.github.com/repos/gdemin/excel.link/issues/1","labels_url":"https://api.github.com/repos/gdemin/excel.link/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/gdemin/excel.link/issues/1/comments","events_url":"https://api.github.com/repos/gdemin/excel.link/issues/1/events","html_url":"https://github.com/gdemin/excel.link/issues/1","id":86648818,"number":1,"title":"Use active bindings","user":{"login":"stefanfritsch","id":7372706,"avatar_url":"https://avatars.githubusercontent.com/u/7372706?v=3","gravatar_id":"","url":"https://api.github.com/users/stefanfritsch","html_url":"https://github.com/stefanfritsch","followers_url":"https://api.github.com/users/stefanfritsch/followers","following_url":"https://api.github.com/users/stefanfritsch/following{/other_user}","gists_url":"https://api.github.com/users/stefanfritsch/gists{/gist_id}","starred_url":"https://api.github.com/users/stefanfritsch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefanfritsch/subscriptions","organizations_url":"https://api.github.com/users/stefanfritsch/orgs","repos_url":"https://api.github.com/users/stefanfritsch/repos","events_url":"https://api.github.com/users/stefanfritsch/events{/privacy}","received_events_url":"https://api.github.com/users/stefanfritsch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-06-09T16:01:16Z","updated_at":"2015-06-11T13:56:48Z","closed_at":null,"body":"Hi,\r\n\r\ngreat package. I know a lot of people that might try R if it was integrated into Excel.\r\n\r\nAn issue I have is that currently the output of `xl.connect.table` don't really behave like other R objects and I wanted to ask if you had looked into using active bindings instead:\r\n\r\n```R\r\nDT<-data.frame(x=1:10, y=2:11)\r\n\r\nmakeActiveBinding(\r\n  \"DF\",\r\n  function(.new_value=NULL)\r\n  {\r\n    if (is.null(.new_value)) {\r\n      return(DT)\r\n    } else {\r\n      DT<<-.new_value\r\n    }\r\n  },\r\n  parent.frame())\r\n\r\nDF\r\nDF[1,1]<-400\r\nDT\r\n```\r\n\r\nThis means that the value of xl.connect.table can't simply be assigned to a variable but you could create something akin to `pryr`'s `%<a-%` operator:\r\n\r\n```R\r\nDF %<xl-% a1\r\nDF %<xlc-% a1:b24\r\n```\r\n\r\nThx\r\nStefan"},"comment":{"url":"https://api.github.com/repos/gdemin/excel.link/issues/comments/111144037","html_url":"https://github.com/gdemin/excel.link/issues/1#issuecomment-111144037","issue_url":"https://api.github.com/repos/gdemin/excel.link/issues/1","id":111144037,"user":{"login":"gdemin","id":3617375,"avatar_url":"https://avatars.githubusercontent.com/u/3617375?v=3","gravatar_id":"","url":"https://api.github.com/users/gdemin","html_url":"https://github.com/gdemin","followers_url":"https://api.github.com/users/gdemin/followers","following_url":"https://api.github.com/users/gdemin/following{/other_user}","gists_url":"https://api.github.com/users/gdemin/gists{/gist_id}","starred_url":"https://api.github.com/users/gdemin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gdemin/subscriptions","organizations_url":"https://api.github.com/users/gdemin/orgs","repos_url":"https://api.github.com/users/gdemin/repos","events_url":"https://api.github.com/users/gdemin/events{/privacy}","received_events_url":"https://api.github.com/users/gdemin/received_events","type":"User","site_admin":false},"created_at":"2015-06-11T13:56:48Z","updated_at":"2015-06-11T13:56:48Z","body":"For current region:\r\n\r\n```\r\nCurrentRegionAssignmentGenerator<-function(row.names = FALSE, col.names = FALSE, na=\"\", drop = TRUE)\r\n{\r\n  \r\n  env<-parent.frame()\r\n  \r\n  function(.x, .value)\r\n  {\r\n    \r\n    .x<-deparse(substitute(.x))\r\n    \r\n    # allow specification of rhs in quotes, \"a1:b100\", or not, a1:b100.\r\n    .value<-substitute(.value)\r\n    if (!is.character(.value))\r\n      .value<-deparse(.value)\r\n    \r\n    # makeActiveBinding doesn't overwrite non-active bindings\r\n    if (exists(.x, env))\r\n      remove(list=.x, envir=env)\r\n    \r\n    if (row.names){\r\n      if(col.names){\r\n        .xlfct <- excel.link::xlrc\r\n      } else {\r\n        .xlfct <- excel.link::xlr\r\n      }\r\n      \r\n    } else {\r\n      if(col.names){\r\n        .xlfct <- excel.link::xlc\r\n      } else {\r\n        .xlfct <- excel.link::xl\r\n      }        \r\n    }\r\n    \r\n    # assign active binding:\r\n    assignment<-function(.new_value=NULL)\r\n    {\r\n      if (is.null(.new_value)) {\r\n        xl.current.region(.value, row.names = row.names, col.names = col.names, na = na, drop = drop)\r\n      } else {\r\n        \r\n        xl()$Range(.value)$CurrentRegion()$Clear() # to prevent overlapping with old values\r\n        .xlfct[[.value]] <- .new_value\r\n        \r\n      }\r\n    }\r\n    \r\n    makeActiveBinding(\r\n      .x,\r\n      assignment,\r\n      env\r\n    )\r\n  }\r\n}\r\n\r\n\r\n`%<cr-%`<-CurrentRegionAssignmentGenerator(row.names = FALSE, col.names = FALSE)\r\n`%<crc-%`<-CurrentRegionAssignmentGenerator(row.names = FALSE, col.names = TRUE)\r\n`%<crr-%`<-CurrentRegionAssignmentGenerator(row.names =TRUE, col.names = FALSE)\r\n`%<crrc-%`<-CurrentRegionAssignmentGenerator(row.names =TRUE, col.names = TRUE)\r\n```"}}