diff --git a/R/ids.R b/R/ids.R index 469b274..495223e 100644 --- a/R/ids.R +++ b/R/ids.R @@ -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) { @@ -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), diff --git a/tests/testthat/test-ids.R b/tests/testthat/test-ids.R index adcf76b..6545865 100644 --- a/tests/testthat/test-ids.R +++ b/tests/testthat/test-ids.R @@ -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", {