Skip to content

Instantly share code, notes, and snippets.

@kirel
Created January 3, 2019 13:39
Show Gist options
  • Save kirel/44e67c80dff38b48fe518594012bd4e1 to your computer and use it in GitHub Desktop.
Save kirel/44e67c80dff38b48fe518594012bd4e1 to your computer and use it in GitHub Desktop.
collector = function(df) {
if (!is.data.frame(df)) stop("df must be data.frame")
structure(list(df=df, accessed=list()), class = "collector")
}
`[[.collector` = function(c, attr, ...) {
c$accessed = c(c$accessed, attr)
c$df[[attr]]
}
c = collector(data_frame(a=1))
c[['a']]
c$accessed # -> list() != list('a') WHY!?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment