Skip to content

Commit

Permalink
Allow multi-class arguments (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemahoney218 authored Mar 14, 2024
1 parent dce5200 commit 91c9ddf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# rsi (development version)

* Functions will no longer error if you construct their arguments with
`glue::glue()` (or otherwise if they have more than one class).

* `landsat_mask_function()` gains an argument, `include`, which lets you specify
whether you'd like to include pixels that represent land (`"land"`), water
(`"water"`), or both (`"both"`). Thanks to @mateuszrydzik for the report via
Expand Down
2 changes: 1 addition & 1 deletion R/check_type_and_length.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ check_type_and_length <- function(...,

arg_class <- class(arg)
dot_class <- class(dots[[dot]])
if (arg_class != dot_class) {
if (!any(arg_class %in% dot_class)) {
if ("integer" %in% arg_class && "numeric" %in% dot_class) {
next # Purposefully doing nothing -- rely on implicit conversion
} else if ("integer" %in% dot_class && rlang::is_integerish(arg)) {
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-check_type_and_length.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ test_that("integer-ish are valid integers", {
}
expect_true(f1())
})

test_that("multi-class arguments are fine", {
f1 <- function(x) {
check_type_and_length(x = character())
}
y <- "a"
class(y) <- c("glue", class(y))

expect_true(f1(y))
})

0 comments on commit 91c9ddf

Please sign in to comment.