search for: scoped_bind

Displaying 4 results from an estimated 4 matches for "scoped_bind".

Did you mean: sched_bind
2019 Oct 07
4
[External] Re: should base R have a piping operator ?
...ns if an > argument in a pipe stage contains a pipe. (Not completely > unreasonable, e.g. for a left_join). It should work exactly as it does in a local environment. ``` `%foo%` <- function(x, y) { env <- parent.frame() # Use `:=` to avoid partial matching on .env/.frame rlang::scoped_bindings(. := x, .env = env) eval(substitute(y), env) } "A" %foo% { print(.) "B" %foo% print(.) print(.) } #> [1] "A" #> [1] "B" #> [1] "A" print(.) #> Error in print(.) : object '.' not found ``` The advantage is that si...
2019 Oct 07
1
[External] Re: should base R have a piping operator ?
On 7 Oct 2019, at 18:17, Tierney, Luke <luke-tierney at uiowa.edu> wrote: > Here is a stylized example: The previous value of the binding should only be restored if it existed: g <- function(x, y) { rlang::scoped_bindings(xx = x, .env = parent.frame()) y get("xx") + 10 } # Good g(1, 2) #> [1] 11 # Still good? g(1, g(1, 2)) #> [1] 11 > If you play these games whether you get the result you want, or an > obvious error, or just the wrong answer depends on argument evaluation > order...
2019 Oct 07
0
[External] Re: should base R have a piping operator ?
...ains a pipe. (Not completely >> unreasonable, e.g. for a left_join). > > It should work exactly as it does in a local environment. > > ``` > `%foo%` <- function(x, y) { > env <- parent.frame() > > # Use `:=` to avoid partial matching on .env/.frame > rlang::scoped_bindings(. := x, .env = env) > > eval(substitute(y), env) > } > > "A" %foo% { > print(.) > "B" %foo% print(.) > print(.) > } > #> [1] "A" > #> [1] "B" > #> [1] "A" > > print(.) > #> Error in pr...
2019 Oct 07
4
should base R have a piping operator ?
Hi Gabe, > There is another way the pipe could go into base R that could not be > done in package space and has the potential to mitigate some pretty > serious downsides to the pipes relating to debugging I assume you're thinking about the large stack trace of the magrittr pipe? You don't need a parser transformation to solve this problem though, the pipe could be implemented as