From f50a51035dae4978a3cca29949fd7755adcd06ec Mon Sep 17 00:00:00 2001 From: Tamas Stirling Date: Fri, 19 Jul 2024 21:45:51 +0200 Subject: [PATCH] Fix ncbi_recover_id() for duplicates --- NAMESPACE | 1 + R/ncbi_recover_id.R | 3 ++- tests/testthat/test-ncbi_recover_id.R | 7 +++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index 2ea93ba..26bf222 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,6 +23,7 @@ export(parse_report) importFrom(curl,curl_download) importFrom(curl,handle_setopt) importFrom(curl,new_handle) +importFrom(dplyr,"%>%") importFrom(dplyr,left_join) importFrom(httr,RETRY) importFrom(httr,content) diff --git a/R/ncbi_recover_id.R b/R/ncbi_recover_id.R index be7435f..ba0aa66 100644 --- a/R/ncbi_recover_id.R +++ b/R/ncbi_recover_id.R @@ -19,6 +19,7 @@ #' uid <- ncbi_get_uid("GCF_000002435.2", db = "assembly") #' ncbi_recover_id(uid) #' } +#' @importFrom dplyr %>% #' @export ncbi_recover_id <- function( query, @@ -67,7 +68,7 @@ ncbi_recover_id <- function( out <- tibble::tibble( uid = as.numeric(unname(sapply(summaries, function(x) x$uid))), id = id - ) + ) %>% dplyr::distinct() if ("ncbi_uid" %in% class(query)) { out <- dplyr::left_join( tibble::tibble(query = query$uid), diff --git a/tests/testthat/test-ncbi_recover_id.R b/tests/testthat/test-ncbi_recover_id.R index 818898a..0033534 100644 --- a/tests/testthat/test-ncbi_recover_id.R +++ b/tests/testthat/test-ncbi_recover_id.R @@ -14,3 +14,10 @@ test_that("ncbi_recover_id() works with UIDs", { expect_equal(examples$assembly, ids) }) + +test_that("ncbi_recover_id() works with duplicates", { + uids <- c(2597423, 2597423) + ids <- ncbi_recover_id(uids, db = "biosample") + + expect_equal(ids, c("SAMN02597423", "SAMN02597423")) +})