burst_pipes: Replace pipes with intermediate assignment

Description Usage Arguments Details Value See Also Examples

View source: R/debug_pipeline.R

Description

burst_pipes rearranges a magrittr pipeline into equivalent unpiped code. Called directly, it will print the restructured code to the console. Called via the "Burst pipes" RStudio add-in while a pipeline is highlighted, it will replace the highlighted code with the restructured code. The "Burst pipes and set names" add-in opens a Shiny gadget in which names can be set.

Usage

1
burst_pipes(pipeline, names, ...)

Arguments

pipeline

A pipeline. Can be an unquoted or quoted expression, or a character vector of code. If missing, uses the text highlighted in RStudio's source editor.

names

A character vector of names to be used for intermediary assignment of a length equal to that of the number of top-level calls in the pipeline.

...

Only used to allow assignment with = at the beginning of a pipeline.

Details

Note that nested pipelines are currently ignored. Calling on pipelines from the inside out should still allow restructuring.

Warning: Calling burst_pipes from the RStudio add-in is currently irreversible aside from "Edit > Undo" and version control. Save code beforehand and check equivalence afterwards.

Value

A list of expressions of the restructured, unpiped code, invisibly.

See Also

split_pipeline splits a pipeline without restructuring.

Examples

1
2
3
4
5
6
7
8
library(magrittr)

burst_pipes(x <- 1:5 %>% rev %>% {. * 2} %>% .[3] %>% rnorm(1, ., sd = ./10))

burst_pipes(
    x = 1:5 %>% rev %>% {. * 2} %>% .[3] %>% rnorm(1, ., sd = ./10),
    names = c("reversed", "doubled", "third", "x")
)

alistaire47/pipecleaner documentation built on April 21, 2020, 1:29 a.m.