Skip to contents

Pipe a value forward into a functio or call expression and return the original value instead of the result. This is useful when an expression is used for its side-effect, say plotting or printing.

Usage

tee(x, expr)

Arguments

x

An object

expr

An expresion

Details

The tee pipe works like |>, except the return value is x itself, and not the result of expr call.

Thanks

I want to give credit to Michael Milton and Matthew Kay for the idea and the code.

Examples

rnorm(200) |>
  matrix(ncol = 2) |>
  as.data.frame() |>
  tee(\(x) {
    ggplot(x, aes(V1, V2)) +
      geom_point()
  }) |>
  colSums()
#>        V1        V2 
#>  9.197561 17.132890