-
Notifications
You must be signed in to change notification settings - Fork 43
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
Update requests to use httr::RETRY and harmonise verbose messages #271
Conversation
This reverts commit 797eaf2.
This reverts commit 2ae7784.
I didn't touch ChemSpider, because I figured the functions can be simplified quite a bit. It's already done but I'll open a separate PR for that. |
Travis is not working because Trusty is no longer supported, and I cannot get rJava to work under more recent versions. I'd rather let it go and fix Travis in a separate PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR looks nice! Some minor comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love love love webchem_url()
, and webchem_message()
, and I love that now all of the functions use the same httr
style including the HTML status reporting. Wonderful stuff. However, for multiple queries I still think most users would prefer that a function fail quickly if a service is down, rather than going very slowly and returning many NAs.
If you decide to keep this behavior, however, there are a number of places where the function still errors when a service is down (tested by turning off wifi and running example). I think it almost always happens because some tidying step or row-binding step is expecting something other than a length 1, unnamed vector. This could be fixed by returning a different data structure inside the if (inherits(res, "try-error"))
statement. Alternatively, you could wrap foo()
in try()
or use purrr::possibly()
rather than wrapping RETRY()
in try()
inside of foo()
. So for example:
db_query <- function(query, verbose = TRUE) {
foo <- function(query) {
<function to do a single query. Errors when service is down>
}
foo_safe <- possibly(foo, otherwise = tibble(query = NA, var1 = NA, var2 = NA), quiet = !verbose)
out <- lapply(query, foo_safe)
}
This PR addresses issues #257 and #268.
This PR updates most webservice requests to use
httr::RETRY()
. The main benefit is that it allows a webservice to be queried multiple times when the previous attempts were unsuccessful. This is especially useful when some webservices randomly become unavailable for a few seconds. Another benefit of the function is that it assigns HTTP status codes and status messages to all webservice requests, allowing harmonised verbose messages.Feel free to add a comment/review/suggest alternatives.
PR task list:
devtools::document()