library("knitr") hook_output <- knitr::knit_hooks$get("output") knitr::knit_hooks$set(output = function(x, options) { lines <- options$output.lines if (is.null(lines)) { return(hook_output(x, options)) # pass to default hook } x <- unlist(strsplit(x, "\n")) more <- "..." if (length(lines)==1) { # first n lines if (length(x) > lines) { # truncate the output, but add .... x <- c(head(x, lines), more) } } else { x <- c(if (abs(lines[1])>1) more else NULL, x[lines], if (length(x)>lines[abs(length(lines))]) more else NULL ) } # paste these lines together x <- paste(c(x, ""), collapse = "\n") hook_output(x, options) }) knitr::opts_chunk$set( warning = FALSE, message = FALSE, collapse = TRUE, comment = "#>" )
etcd
is a key-value DB written in Go
. It has an HTTP API, which this R package wraps.
See the etcd Github repo for help on installing etcd
.
There are various ways to install it, and they depend on your operating sytsem.
You can install via homebrew
, install from source, and via Docker.
at the command line
etcd
how to start etcd may differ depending on your setup
Install etseed
install.packages("etseed")
Development version
install.packages("devtools") devtools::install_github("ropensci/etseed")
library("etseed")
First task when using this package is to initialize a client
with the etcd()
function. it's a wrapper around an R6 class.
(client <- etcd())
Default settings in etcd()
connect you to localhost
, and port 2379
,
using etcd API version 2, with an http
scheme.
client$version()
out <- tryCatch(client$key("/neighbor"), error=function(e) e) if (!inherits(out, "http_error")) client$delete("/neighbor", dir=TRUE) Sys.sleep(3)
client$create("/neighbor", dir = TRUE)
out <- tryCatch(client$key("/mykey"), error=function(e) e) if (!is(out, "http_error")) client$delete("/mykey") out <- tryCatch(client$key("/stuff"), error=function(e) e) if (!is(out, "http_error")) client$delete("/stuff")
client$create(key = "/mykey", value = "this is awesome")
Sys.sleep(3)
Use ttl
parameter to make it dissappear after x
seconds
client$create(key = "/stuff", value = "tables", ttl = 5)
And the key will be gone after 5 seconds, see:
client$key("/stuff") #> Error in etcd_GET(sprintf("%s%s/%s/", etcdbase(), "keys", key), ...) : #> client error: (404) Not Found
out <- tryCatch(client$key("/foo"), error=function(e) e) if (!is(out, "http_error")) client$delete("/foo")
Create a key
client$create(key = "/foo", value = "bar")
Then update the key
client$update(key = "/foo", value = "bar stool")
client$create_inorder("/queue", "thing1")
client$create_inorder("/queue", "thing2")
client$create_inorder("/queue", "thing3")
client$keys()
client$key("/mykey")
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.