Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR caches GET requests to the phylopic server.
Motivation
I'm often regenerating plots that contain phylopic silhouettes as I adjust the layout and formatting, or re-render markdown output. As it often takes a second or two to download each silhouette, calls to phylopic introduce significant delay into a workflow. As the server data is unlikely to change in the course of an R session, it seems beneficial to the user (and to the phylopic servers?) to reduce the number of GET requests
Implementation
A key is generated for each GET requests using
digest, and the response is stored in a local cache environment. If the server is offline, no cache entry is created, so the call will be repeated on future attempts.I'd considered creating a persistent cache, but this could be problematic as (i) CRAN policies are particular about how files can be created locally; (ii) longer-term caches are more likely to diverge from the server. It's not clear that there would be a sufficient benefit over session-limited caches.
Additional changes
As I went, I also added a couple of imported functions that were missing from
NAMESPACE, and replaced hard-coded API references with a function (for a single point of definition).