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.

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.

Value

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

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.

See also

split_pipeline splits a pipeline without restructuring.

Examples

# \donttest{ library(magrittr) burst_pipes(x <- 1:5 %>% rev %>% {. * 2} %>% .[3] %>% rnorm(1, ., sd = ./10))
#> dot1 <- rev(1:5) #> dot2 <- {dot1 * 2} #> dot3 <- dot2[3] #> x <- rnorm(1, dot3, sd = dot3/10)
burst_pipes( x = 1:5 %>% rev %>% {. * 2} %>% .[3] %>% rnorm(1, ., sd = ./10), names = c("reversed", "doubled", "third", "x") )
#> reversed <- rev(1:5) #> doubled <- {reversed * 2} #> third <- doubled[3] #> x <- rnorm(1, third, sd = third/10)
# }