Skip to content

Commit

Permalink
handle empty key queries
Browse files Browse the repository at this point in the history
* should return character(0) not ":"
  • Loading branch information
jefferis committed Nov 18, 2024
1 parent be8a5ba commit ac246e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ keys <- function(x, idcol='id') {
)
x$dataset=abbreviate_datasets(x$dataset)
}
paste0(x[['dataset']],":", x[[idcol]])
if(nrow(x)>0)
paste0(x[['dataset']],":", x[[idcol]])
else
character()
}

is_key <- function(x, compound=FALSE) {
Expand Down Expand Up @@ -269,6 +272,7 @@ expand_ids <- function(ids, dataset) {
ids=mapply(expand_ids, ids=ids, dataset=names(ids), SIMPLIFY = FALSE)
return(ids)
}
if(length(ids)==0) return(character())
dataset=match_datasets(dataset)
FUN <- switch(dataset,
manc=function(ids) malevnc::manc_ids(ids, mustWork = F),
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-ids.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ test_that("key handling works", {
expect_output(print(res), regexp = 'flywire.*hemibrain')

expect_equal(keys(cf_ids(hemibrain = '/MBON01')), cf_ids(hemibrain = '/MBON01', keys = T))

expect_warning(
expect_equal(cf_ids(hemibrain = "/rhubarb", keys = T), character()),
"No matching ids")
})

test_that("fanc/banc ids/metadata", {
Expand Down

0 comments on commit ac246e8

Please sign in to comment.