knitr::opts_chunk$set( comment = "#>", tidy = FALSE, error = FALSE)
An extremely simple fallback algorithm, to query a backup HTTP server, if the first choice HTTP server is down.
The algorithm works fine if a server is completely down, but might fail if the network is unreliable and/or slow. Consider this before you use this package. Suggestions for improvements are welcome.
library(devtools) install_github("metacran/spareserver")
You can define services, and will use multiple servers. Each server has a default priority, and the servers are tried in the order of decreasing priority.
library(spareserver) add_service("cran-packages", server("http://cran.r-project.org/web/packages", priority = 10), server("http://cran.rstudio.com/web/packages", priority = 5) )
Then you can make a robust query. Here we use the httr
package.
library(httr) spare_q("cran-packages", "/ggplot2/index.html", GET) remove_service("cran-packages")
In the next example, the first server is unreachable, so we will use the fallback server.
add_service("cran-packages", server("http://192.0.2.1/foobar", priority = 10), server("http://cran.rstudio.com/web/packages", priority = 5) )
spare_q("cran-packages", "/ggplot2/index.html", GET) remove_service("cran-packages")
If all servers are down, then we start over, with fifty times bigger timeout. We only do two rounds currently, and the statuses are reset between rounds.
MIT
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.