tests/testthat/testPackage/R/palindrome.R

#' Return a palindrome
#'
#' @return A string
#' @export
#'
#' @doctest
#' p <- palindrome()
#' @expectRaw match(p, "Panama")
#' @omit
#' print(p)
#' @resume
#' pal_letters <- p |>
#'   tolower() |>
#'   (\(x) gsub("[^A-z]", "", x))() |>
#'   strsplit("") |>
#'   unlist()
#' @expectRaw equal(pal_letters, rev(pal_letters))
palindrome <- function () {
   "A man, a plan, a canal - Panama"
}


#' @export
#' @rdname palindrome
#' @doctest palindrome_letters
#' @testRaw skip_on_cran()
#' @expect equal(., rev(.))
#' tenet <- palindrome_letters()
palindrome_letters <- function () {
  c("t", "e", "n", "e", "t")
}

Try the doctest package in your browser

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

doctest documentation built on May 29, 2024, 7:09 a.m.