## ----knitr-setup, include = FALSE-----------------------------------------------------------------
knitr::opts_chunk$set(
    comment = "#",
    prompt = FALSE,
    tidy = FALSE,
    cache = FALSE,
    collapse = TRUE
)

old <- options(width = 100L)

## ----setup-pipeline-------------------------------------------------------------------------------
library(pipeflow)

pip <- pip_new("my-pip") |>
    pip_add("load", \(n = 5) seq_len(n), tags = c("io", "daily")) |>
    pip_add("clean", \(x = ~load) x * 2, tags = c("io", "core")) |>
    pip_add("fit", \(x = ~clean) sum(x), tags = c("model", "core")) |>
    pip_add("report", \(x = ~fit) paste("result:", x), tags = "report")

## -------------------------------------------------------------------------------------------------
(pip_run(pip, lgr = NULL))

## -------------------------------------------------------------------------------------------------
pip_view(pip, tags = "core")

## -------------------------------------------------------------------------------------------------
pip_view(pip, tags = "core", state = "done")

pip_view(pip, step = c("clean", "fit"))

## -------------------------------------------------------------------------------------------------
pip_view(pip, tags = "report", step = "clean", join = "union")

## -------------------------------------------------------------------------------------------------
pip_view(pip, step = "^f", fixed = FALSE)

## -------------------------------------------------------------------------------------------------
pip_reset(pip) # reset to initial state

pip_view(pip, depends = "load", state = "new")

## -------------------------------------------------------------------------------------------------
pip_run(pip, lgr = NULL)
pip[c("load", "fit")]

pip[1:3]

## -------------------------------------------------------------------------------------------------
pip[tags %like% "core"]

pip[step %in% c("clean", "fit") & state == "done"]

## -------------------------------------------------------------------------------------------------
pip[-2]

## -------------------------------------------------------------------------------------------------
pip2 <- pip[]

pip[, c("step", "tags")]

pip[c("load", "fit"), "out"]

## -------------------------------------------------------------------------------------------------
pip[c("fit", "report"), view = FALSE]

## -------------------------------------------------------------------------------------------------
v1 <- pip_view(pip, tags = "io") # load, clean
v1

v2 <- v1 |> pip_view(tags = "core") # clean only
v2

## -------------------------------------------------------------------------------------------------
pip[["view"]] # NULL — not a view

w <- pip
w[["view"]] <- c("load", "clean")
w

w[["view"]] <- NULL # back to the full pipeline
w

## -------------------------------------------------------------------------------------------------
pip_reset(pip)
pip_run(pip_view(pip, step = "report"))

## ----include = FALSE----------------------------------------------------------
options(old)

