Last active
February 10, 2020 16:58
-
-
Save romainfrancois/cc26a44d59b0f3646d50c059d085cf30 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
library(purrr) | |
library(assertthat) | |
let <- function(...) quos(...) | |
`:=` <- function(left, right){ | |
names <- map_chr(left, quo_name) | |
assert_that( length(right) >= length(names) ) | |
env <- parent.frame() | |
for( i in seq_along(names) ){ | |
assign( names[i], right[[i]], envir = env) | |
} | |
invisible(NULL) | |
} | |
x <- rnorm(100) | |
let(low,up) := range(x) | |
# alternatively | |
library(purrr) | |
library(assertthat) | |
tie <- structure( NA, class = "tie_proxy") | |
`[<-.tie_proxy` <- function(x, ..., value){ | |
dots <- quos(...) | |
assert_that( length(value) >= length(dots) ) | |
env <- parent.frame() | |
for( i in seq_along(names) ){ | |
dot <- dots[[i]] | |
if( !quo_is_missing(dot) ){ | |
assign( quo_name(dot), value[[i]], envir = env) | |
} | |
} | |
invisible(x) | |
} | |
x <- rnorm(100) | |
tie[low,up] <- range(x) | |
Yeah that was the first thing I tried. 😞
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is a pity that just defining
let<-
is not possible.