ropensci / rentrez

talk with NCBI entrez using R
https://docs.ropensci.org/rentrez
Other
194 stars 38 forks source link

Improve error message when using a nonsense database #157

Open richelbilderbeek opened 3 years ago

richelbilderbeek commented 3 years ago

Dear rentrez maintainer,

I enjoy rentrez quite a bit and I suggest to improve an error message to make it even more awesome:

The code below works fine (if NCBI is up), where I use the 'gene' database to look up the gene 'something':

rentrez::entrez_search(db = "gene", term = "something")

When the database name is nonsense, I get an obscure error. For example, this code ..

rentrez::entrez_search(db = "nonsense", term = "something")

results in the error message:

Error in ans[[1]] : subscript out of bounds

I suggest to add a more descriptive error message, such as for example:

testthat::expect_error(
  rentrez::entrez_search(db = "nonsense", term = "something"),
  "Database 'nonsense' does not exist"
)

To make it even more awesome, give the user a hint which databases can be used, such as referring to a (not yet existing?) rentrez function such as get_db_names:

# Optional
expect_error(
  rentrez::entrez_search(db = "nonsense", term = "something"),
  "Tip: use 'get_db_names' to get a list of all database names"
)
dwinter commented 3 years ago

Hi @richelbilderbeek ,

That's a good idea, I think we can check the NCBI output for <ERROR> fields, and at least return use them as an R warning.

A bit slammed at the moment, but can keep it on the TODO list.

richelbilderbeek commented 3 years ago

Great to hear this feature one day will be there. Thanks so much!