
Why pipetime?
why_pipetime.Rmd
R pipelines (|>
) allow chaining operations in a
readable, sequential way. Existing timing tools
(e.g. system.time()
, tictoc
) do not integrate
naturally with pipelines and tidy workflows. pipetime
solves this by letting you measure time inline, without interrupting the
pipeline.
Examples
slow_op <- function(x) {
Sys.sleep(0.1) # Simulate a time-consuming operation
x^2
}
system.time()
# Must wrap the entire pipeline, breaking the flow
the_time <- system.time({
df <- data.frame(x = 1:3) |>
mutate(y = slow_op(x)) |>
summarise(mean_y = mean(y))
})
the_time
#> user system elapsed
#> 0.008 0.000 0.109
df
#> mean_y
#> 1 4.666667
# system.time() cannot be inserted inline in a pipeline:
data.frame(x = 1:3) |>
mutate(y = slow_op(x)) |>
# system.time() would break the pipeline here
summarise(mean_y = mean(y))
#> mean_y
#> 1 4.666667
time_pipe
# Inline timing checkpoints, pipeline stays intact
data.frame(x = 1:3) |>
mutate(y = slow_op(x)) |>
time_pipe("after mutate") |>
summarise(mean_y = mean(y)) |>
time_pipe("total pipeline")
#> [2025-10-08 00:33:48.516] after mutate: +0.1014 secs
#> [2025-10-08 00:33:48.516] total pipeline: +0.1071 secs
#> mean_y
#> 1 4.666667
Why pipetime
?
Works directly inside pipelines.
Supports multiple checkpoints.
Prints or logs timings in
.pipetime_env
(see?get_log
).