Created
October 12, 2015 18:55
-
-
Save jsonbecker/e53f1ffe535cae379650 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
## Current pattern | |
function(myList){ | |
do_stuff_with(mylist$attribute1, myList$attribute2) | |
do_stuff_with(mylist$attribute3, myList$attribute4) | |
} | |
## Desired pattern | |
function(myList){ | |
do_stuff_with(attribute1, attribute2) | |
do_stuff_with(attribute4, attribute4) | |
} |
This:
assign_vars <- function(x) {
for (i in seq_along(x)) {
assign(names(x)[[i]], x[[i]], envir = parent.frame())
}
}
foo_bar <- function(x) {
assign_vars(x)
print(a)
print(b)
}
a_list <- list(a = "hello", b = "world")
foo_bar(a_list)
#> [1] "hello"
#> [1] "world"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe it's something like: