tests/testthat/test-str_extract_part.R

test_that("str_extract_part() returns only strings before the % sign", {
  expect_equal(
    str_extract_part(string = c("5%", "92%", "75%"), pattern =  "%", before = TRUE),
    c("5", "92", "75")
  )
})

test_that("str_extract_part() return only strings after -", {
  expect_equal(
    str_extract_part(string = c("Good-Morning", "Good-Afternoon"), pattern =  "-", before = FALSE),
    c("Morning", "Afternoon")
  )
})

Try the forstringr package in your browser

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

forstringr documentation built on Aug. 7, 2023, 5:08 p.m.