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

Fix is_named_list bug #3181 #3183

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix is_named_list bug #3181
  • Loading branch information
johnkerl committed Oct 16, 2024
commit 943f3b2b978c1d77c7e2e348888255481f861e55
4 changes: 3 additions & 1 deletion apis/r/R/utils-assertions.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ is_named <- function(x, allow_empty = TRUE) {
}

is_named_list <- function(x) {
is.list(x) && is_named(x)
# Use allow_empty=FALSE otherwise "half-named" lists like list(a=1, 2)
# will get through. We want all slots to have names.
is.list(x) && is_named(x, allow_empty = FALSE)
}

is_character_or_null <- function(x) {
Expand Down
6 changes: 6 additions & 0 deletions apis/r/tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,9 @@ test_that("validate read coords with dimension names and schema", {
expect_equal(test_coords$int_column, 1:10)
expect_equal(test_coords$soma_joinid, as.integer64(1:10))
})

test_that("half-named lists are not treated as named", {
expect_true(is_named_list(list(a=1, b=2)))
expect_false(is_named_list(list(a=1, 2)))
expect_false(is_named_list(list(1, 2)))
})