Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions R/Validity.R
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be better to use tools::file_ext() and tolower() to check the extension with vector of allowed extensions.

Copy link
Contributor

@LiNk-NY LiNk-NY May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider doing something like:

## [... outside the function]
.ALLOWED_FORMATS <- c("png", "jpg", "jpeg", "tif", "tiff")
## [... inside the function]
ext <- tools::file_ext(x) |> tolower()
ext %in% .ALLOWED_FORMATS

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I also made this change as well 👍

Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down