Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to lazy implementation #218

Merged
merged 14 commits into from
Aug 3, 2020
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export(multiply_by)
export(multiply_by_matrix)
export(not)
export(or)
export(pipe_eager_lexical)
export(pipe_lazy_masking)
export(pipe_nested)
export(raise_to_power)
export(set_attr)
export(set_attributes)
Expand Down
36 changes: 18 additions & 18 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@

## Fast and lean implementation of the pipe

The pipe has been rewritten in C.
The pipe has been rewritten in C with the following goals in mind:

- Minimal performance cost.
- Minimal impact on backtraces.
- No impact on reference counts.

As part of this rewrite we have slightly changed the behaviour of the
pipe so that the piped expressions are now evaluated in the current
environment. Previously, the pipe evaluated in its own private
environment where `.` was defined. This is technically a breaking
change, but this should only affect very specific corner cases and it
brings the behaviour of the pipe closer to other control flow
mechanisms like `if ()` or `for ()` which also evaluate in the current
environment. This also brings it closer to the probable semantics of
the native R pipe that is likely to be introduced in the next version
of R. The most visible consequences of this new behaviour are:

- `parent.frame()` now returns the same environment in piped and
non-piped evaluation (#146, #171).

- `return()` returns from the enclosing function. It would previously
return from the current pipe expression and continue evaluation from
there.
As part of this rewrite we have changed the behaviour of the pipe to
make it closer to the implementation that will likely be included in a
future version of R. The pipe now evaluates piped expressions lazily (#120).
The main consequence of this change is that warnings and errors can
now be handled by trailing pipe calls:

```{r}
stop("foo") %>% try()
warning("bar") %>% suppressWarnings()
```


## Bug fixes

* Piped arguments are now persistent. They can be evaluated after the
pipeline has returned, which fixes subtle issues with function
factories (#159, #195).


# magrittr 1.5
Expand Down
39 changes: 39 additions & 0 deletions R/pipe.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,45 @@
rhs <- substitute(rhs)
kind <- 1L
env <- parent.frame()
lazy <- TRUE
.External2(magrittr_pipe)
}

#' Lazy and eager pipes
#'
#' Assign these pipe variants to an infix symbol like `%>%`.
#'
#' @inheritParams %>%
#' @keywords internal
#' @export
pipe_eager_lexical <- function(lhs, rhs) {
lhs <- substitute(lhs)
rhs <- substitute(rhs)
kind <- 1L
env <- parent.frame()
sym <- sys.call()[[1]]
.External2(magrittr_pipe)
}
#' @rdname pipe_eager_lexical
#' @export
pipe_lazy_masking <- function(lhs, rhs) {
lhs <- substitute(lhs)
rhs <- substitute(rhs)
kind <- 1L
env <- parent.frame()
lazy <- TRUE
sym <- sys.call()[[1]]
.External2(magrittr_pipe)
}
#' @rdname pipe_eager_lexical
#' @export
pipe_nested <- function(lhs, rhs) {
lhs <- substitute(lhs)
rhs <- substitute(rhs)
kind <- 1L
env <- parent.frame()
nested <- TRUE
sym <- sys.call()[[1]]
.External2(magrittr_pipe)
}

Expand Down
23 changes: 23 additions & 0 deletions man/pipe_eager_lexical.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

147 changes: 89 additions & 58 deletions revdep/dplyr/README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,95 @@
# Revdeps

## Failed to check (51)
## Failed to check (81)

|package |version |error |warning |note |
|:----------------|:-------|:-----|:-------|:----|
|ALA4R |? | | | |
|bibliometrix |? | | | |
|bioOED |? | | | |
|bootnet |? | | | |
|NA |? | | | |
|NA |? | | | |
|butcher |? | | | |
|CausalImpact |? | | | |
|NA |? | | | |
|choroplethr |3.6.3 |1 | | |
|CityWaterBalance |0.1.0 |1 | | |
|countyweather |? | | | |
|DecomposeR |1.0.2 |1 | | |
|easyr |? | | | |
|NA |? | | | |
|EdSurvey |? | | | |
|EML |2.0.2 |1 | | |
|EvaluateCore |0.1.1 |1 | | |
|fingertipscharts |0.0.11 |1 | | |
|gastempt |0.5.0 |1 | | |
|geneHummus |1.0.11 |1 | | |
|ghibli |? | | | |
|hadron |? | | | |
|NA |? | | | |
|ICAMS |? | | | |
|idiogramFISH |? | | | |
|NA |? | | | |
|NA |? | | | |
|MetaboList |2.0 |1 | | |
|metagam |? | | | |
|mlVAR |? | | | |
|nesRdata |0.3.1 |1 | | |
|phyr |? | | | |
|pmc |? | | | |
|processR |0.2.3 |1 | | |
|PROsetta |0.1.4 |1 | | |
|provSummarizeR |? | | | |
|qgraph |1.6.5 |1 | | |
|Rarefy |? | | | |
|NA |? | | | |
|RNeXML |? | | | |
|robmed |0.7.0 |1 | | |
|salesforcer |? | | | |
|SDLfilter |2.0.1 |1 | | |
|SimDesign |? | | | |
|NA |? | | | |
|tidySEM |0.1.2 |1 | | |
|tmap |3.1 |1 | | |
|trackdf |? | | | |
|trackr |? | | | |
|wrswoR |? | | | |
|package |version |error |warning |note |
|:--------------------|:-------|:-----|:-------|:----|
|afex |? | | | |
|ALA4R |? | | | |
|apaTables |? | | | |
|bibliometrix |? | | | |
|bioOED |? | | | |
|bmlm |? | | | |
|bootnet |? | | | |
|NA |? | | | |
|NA |? | | | |
|broom |? | | | |
|butcher |? | | | |
|CausalImpact |? | | | |
|NA |? | | | |
|choroplethr |3.6.4 |1 | | |
|CityWaterBalance |0.1.0 |1 | | |
|codebook |? | | | |
|correlation |? | | | |
|countyweather |? | | | |
|DecomposeR |1.0.2 |1 | | |
|dextergui |? | | | |
|easyr |? | | | |
|NA |? | | | |
|EdSurvey |? | | | |
|EGAnet |? | | | |
|EstimateGroupNetwork |? | | | |
|EvaluateCore |? | | | |
|fingertipscharts |0.0.11 |1 | | |
|forwards |? | | | |
|FSA |? | | | |
|gastempt |0.5.0 |1 | | |
|geneHummus |1.0.11 |1 | | |
|ghibli |? | | | |
|gms |? | | | |
|graphicalVAR |? | | | |
|hadron |? | | | |
|huxtable |? | | | |
|NA |? | | | |
|ICAMS |? | | | |
|idiogramFISH |? | | | |
|NA |? | | | |
|jrt |? | | | |
|NA |? | | | |
|lvnet |? | | | |
|MarketMatching |? | | | |
|MDSPCAShiny |? | | | |
|MetaboList |2.0 |1 | | |
|metagam |? | | | |
|MLRShiny |? | | | |
|MLRShiny2 |? | | | |
|mlVAR |? | | | |
|nesRdata |0.3.1 |1 | | |
|parameters |? | | | |
|phyr |? | | | |
|pmc |? | | | |
|prepdat |? | | | |
|processR |? | | | |
|PROsetta |? | | | |
|provSummarizeR |? | | | |
|qgraph |? | | | |
|quickReg |? | | | |
|Rarefy |? | | | |
|regressoR |? | | | |
|NA |? | | | |
|RNeXML |? | | | |
|robmed |0.7.0 |1 | | |
|salesforcer |? | | | |
|SDLfilter |2.0.1 |1 | | |
|semdrw |? | | | |
|SimDesign |? | | | |
|sjPlot |? | | | |
|splithalfr |? | | | |
|STAT |? | | | |
|NA |? | | | |
|NA |? | | | |
|tidySEM |? | | | |
|tmap |3.1 |1 | | |
|trackdf |? | | | |
|trackr |? | | | |
|ufs |? | | | |
|wiseR |? | | | |
|wrswoR |? | | | |

## New problems (1)
## New problems (2)

|package |version |error |warning |note |
|:----------------------------------|:-------|:------|:-------|:----|
|[ggfortify](problems.md#ggfortify) |0.4.10 |__+1__ | | |
|package |version |error |warning |note |
|:----------------------------------|:-------|:-----|:-------|:----|
|[florestal](problems.md#florestal) |0.1.1 | |__+1__ | |
|[gMOIP](problems.md#gmoip) |1.4.3 | |__+1__ | |

Loading