From 3f972d446fe16f8040f551da972c9a82585abfed Mon Sep 17 00:00:00 2001 From: Andrew Ghazi <6763470+andrewGhazi@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:11:54 -0500 Subject: [PATCH] allow additional image extensions (jpeg and tiff) as well as capitalized variants. Amended earlier changes that directly bumped the version number. Also changed the pattern detection to use tolower() as suggested. --- R/Validity.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/R/Validity.R b/R/Validity.R index 39dff8b..2e72513 100644 --- a/R/Validity.R +++ b/R/Validity.R @@ -98,13 +98,18 @@ setValidity2("SpatialExperiment", .spe_validity) # SpatialImage validity -------------------------------------------------------- +.ALLOWED_FORMATS <- c("png", "jpg", "jpeg", "tif", "tiff") + .path_validity <- function(x) { + + ext <- tools::file_ext(x) |> tolower() + is_valid <- all(c( length(x) == 1, is.character(x), file.exists(x), - # TODO: any other possible image formats? - grepl("(\\.png|\\.jpg|\\.tif)$", x))) + ext %in% .ALLOWED_FORMATS + )) if (!is_valid) stop("'path' should be a length-one character",