Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multi-class arguments #48

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
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
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))
})
Loading