Created
January 3, 2019 13:39
-
-
Save kirel/44e67c80dff38b48fe518594012bd4e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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