pipe_cat: Pipe-able version of the 'cat()'

Description Usage Arguments Examples

View source: R/pipe_cat.R

Description

The pipe_cat() function allows messages to be output to the console or to an external file without the need to break out of a pipeline to do so.

Usage

1
2
3
4
5
6
7
8
9
pipe_cat(
  data,
  ...,
  file = "",
  sep = " ",
  fill = FALSE,
  labels = NULL,
  append = FALSE
)

Arguments

data

the data being passed through the pipeline

...

arguments to be passed to the cat() function. Arguments will be evaluated in the context of data before being passed to cat()

file, sep, fill, labels, append

See the cat() documentation for more information regarding these arguments.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
sample(100, 1) %>%
  runif() %>%
  pipe_cat("Current length: ", length(.), "\n") %>%
  pipe_cat("Current average: ", mean(.), "\n") %>%
  pipe_cat("Current standard error: ", sd(.) / length(.), "\n") %>%
  pipe_cat("Returning mean:\n") %>%
  mean()

tibble::tibble(
  x = runif(10),
  y = runif(10)
) %>%
  pipe_cat("Average x: ", mean(x), "\n") %>%
  pipe_cat("Current number of rows: ", nrow, "\n") %>%
  dplyr::mutate(z = x + y)

palmerpenguins::penguins %>%
  dplyr::mutate(species = as.character(species)) %>%
  dplyr::filter(!is.na(bill_length_mm)) %>%
  pipe_cat("Total average Culmen Length: ", mean(bill_length_mm), "\n") %>%
  dplyr::group_by(species) %>%
  pipe_cat(species, " average Culmen Length: ", mean(bill_length_mm), "\n")

MyKo101/mpipe documentation built on Feb. 6, 2021, 2:13 p.m.