Create pipe-able assertions using magrittr’s tee operator, %T>%.

library(assertthat)
library(tidyverse)

assert_len_3 <- . %>%
  { assert_that(length(.) == 3, msg = "Not 3 elements") }

x <-
  c(1, 2, 3) %>%
  map_dbl(~.x + 1) %T>%
  assert_len_3() %>%
  map_dbl(~.x + 1)

x
#> [1] 3 4 5

y <-
  c(1, 2, 3, 4) %>%
  map_dbl(~.x + 1) %T>%
  assert_len_3() %>%
  map_dbl(~.x + 1)
#> Error: Not 3 elements

exists("y")
#> [1] FALSE

Created on 2020-03-30 by the reprex package (v0.3.0)