Registers a knitr source hook that enables logrittr logging in R Markdown and Quarto documents, with no change to pipeline code.
"native" (default): rewrites |> to %>=% in chunks where the chunk
option logrittr = TRUE is set.
"magrittr": calls logrittr_activate() so %>% logs globally.
"both": does both of the above.
logrittr_hook(pipe = c("native", "magrittr", "both"))Invisibly returns NULL.
if (FALSE) { # \dontrun{
# In your setup chunk:
library(logrittr)
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
message = TRUE # needed to show logrittr output (uses message())
)
# For |> pipes (opt-in per chunk with logrittr = TRUE):
logrittr_hook()
# For %>% pipes (global):
logrittr_hook("magrittr")
# For both:
logrittr_hook("both")
# Then in any chunk you want logged (native pipe):
# ```{r, logrittr = TRUE}
# iris |>
# filter(Sepal.Length < 5) |>
# group_by(Species) |>
# summarise(n = n())
# ```
} # }