Created
July 17, 2019 03:10
-
-
Save seasmith/63831e1a5d48ed7f27c494c5d767e421 to your computer and use it in GitHub Desktop.
Evaluate a list lazily
This file contains hidden or 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
# Taken from: https://twitter.com/dirk_sch/status/1151080975952228352 | |
"[[.ll" <- function(x, i) { | |
rlang::eval_tidy(x$call_list[[i]]) | |
} | |
lazylist <- function(...) { | |
calls <- rlang::enexprs(...) | |
structure(list(call_list = calls), class = "ll") | |
} | |
a <- lazylist(1, 2, Sys.sleep(10), 10) | |
a[[2]] | |
#> [1] 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment