Skip to content

Commit

Permalink
Merge pull request #81 from stitam/recover
Browse files Browse the repository at this point in the history
Fix ncbi_recover_id() for duplicates
  • Loading branch information
stitam authored Jul 19, 2024
2 parents 44bcb50 + f50a510 commit 5de7384
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion R/ncbi_recover_id.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-ncbi_recover_id.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})

0 comments on commit 5de7384

Please sign in to comment.