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

epmc_search: populate the hit_count attribute even with zero results #58

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Imports:
tibble,
tidyr,
rlang
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Suggests:
testthat,
knitr,
Expand Down
5 changes: 4 additions & 1 deletion R/epmc_search.r
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ epmc_search <- function(query = NULL,
hits <- epmc_hits(query, synonym = synonym)
if (hits == 0) {
message("There are no results matching your query")
md <- NULL
# return an empty tibble
md <- tibble::tibble()
# populate the hit_count attribute even with zero results
attr(md, "hit_count") <- hits
} else {
limit <- as.integer(limit)
limit <- ifelse(hits <= limit, hits, limit)
Expand Down
Binary file modified docs/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions man/epmc_annotations_by_id.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/epmc_ftxt.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/europepmc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions tests/testthat/test_epmc_db.r
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ context("testing epmc_db")

test_that("epmc_db returns", {
skip_on_cran()
a <- epmc_db("12368864", db = "uniprot", limit = 50)
# as of July 2024, this result only returns 10 results, so limit must
# be <= that
a_limit <- 7
a <- epmc_db("12368864", db = "uniprot", limit = a_limit)
b <- epmc_db("25249410", db = "embl")
c <- epmc_db("14756321", db = "uniprot")
d <- epmc_db("11805837", db = "pride")
Expand Down Expand Up @@ -31,7 +34,7 @@ test_that("epmc_db returns", {



expect_equal(nrow(a), 50)
expect_equal(nrow(a), a_limit)

# fails correctly
expect_error(epmc_db("14756321"), "Please restrict reponse to a database")
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_epmc_search.r
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ test_that("epmc_search returns", {
expect_is(k, "list")
expect_is(l, "data.frame")

#are diminsions correct?
# are dimensions correct?
expect_equal(nrow(e), 250)
expect_equal(ncol(e), 4)
expect_equal(nrow(f), 25)
expect_equal(nrow(h), 100)
expect_equal(length(i), 125)
expect_equal(nrow(j), 0)
expect_equal(nrow(l), 100)


# fails correctly
expect_message(epmc_search("123haha"),
"There are no results matching your query")
expect_null(j)
expect_error(epmc_search(query = "malaria", limit = TRUE))
expect_error(epmc_search(query = "malaria", verbose = "kdk"))
expect_error(epmc_search(query = "malaria", synonym = "yes"))
Expand Down
Loading