R/check_png_filename.R

Defines functions check_png_filename

Documented in check_png_filename

#' Check if the `png_filename` is valid
#'
#' Check if the `png_filename` is valid
#' Will \link{stop} if not.
#' @inheritParams default_params_doc
#' @return Nothing. Will \link{stop} if `png_filename` is invalid.
#' @examples
#' check_png_filename("my.png")
#' @author Richèl J.C. Bilderbeek
#' @export
check_png_filename <- function(
  png_filename
) {
  testthat::expect_equal(1, length(png_filename))
  testthat::expect_true(is.character(png_filename))
  testthat::expect_true(nchar(png_filename) > 0)
  if (
    !stringr::str_detect(
      string = png_filename,
      pattern = "^[[:graph:]]+\\.png$"
    )
  ) {
    stop(
      "'png_filename' must match regex '^[[:graph:]]+\\.png$' \n",
      "png_filename: ", png_filename
    )
  }
}
richelbilderbeek/gcaer documentation built on March 25, 2024, 3:08 p.m.