rentrez
rentrez copied to clipboard
Improve error message when using a nonsense database
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"
)
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.
Great to hear this feature one day will be there. Thanks so much!