tests/testthat/stringr-imported/test-c.R

test_that("basic case works", {
  test <- c("a", "b", "c")

  expect_equal(str_c(test), test)
  expect_equal(str_c(test, sep = " "), test)
  expect_equal(str_c(test, collapse = ""), "abc")
})

test_that("obeys tidyverse recycling rules", {
  expect_equal(str_c(), character())

  expect_equal(str_c("x", character()), character())
  expect_equal(str_c("x", NULL), "x")

  expect_snapshot(cran = TRUE, str_c(c("x", "y"), character()), error = TRUE)
  expect_equal(str_c(c("x", "y"), NULL), c("x", "y"))
})

test_that("vectorised arguments error", {
  expect_snapshot(cran = TRUE, error = TRUE, {
    str_c(letters, sep = c("a", "b"))
    str_c(letters, collapse = c("a", "b"))
  })
})

Try the charr package in your browser

Any scripts or data that you put into this service are public.

charr documentation built on Nov. 7, 2026, 9:06 a.m.