ropensci / europepmc

R Interface to Europe PMC RESTful Web Service
https://docs.ropensci.org/europepmc
27 stars 8 forks source link

Error if no results in epmc_search? #20

Open cstubben opened 7 years ago

cstubben commented 7 years ago

I sometimes run epmc_search in a loop, and if no results are found, it exits with an error. Right now I'm checking error messages, but it might be better if "No results found" returns a message and empty table instead?

if (hits == 0){
  message("There are no results matching your query") 
  md <- tibble()
}else{
  ...
}
attr(md, "hit_count") <- hits
return(md)
njahn82 commented 7 years ago

Agreed, it is more sensible to return NULL and a message when no results are found. Will implement it.

cstubben commented 7 years ago

Great, thanks. At least with an empty table you can still add the hit_count attribute, but NULL works too.

njahn82 commented 7 years ago

@cstubben is now on master branch, hope, it works for you!