etseed

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 = "#>"
)

cran checks Build Status rstudio mirror downloads cran version codecov.io

etcd R client

etcd is a key-value DB written in Go. It has an HTTP API, which this R package wraps.

etcd API docs

Development follows closely the newest version of etcd released by the Coreos folks. As of 2018-08-14 that's etcd v3.3.9

Installing etcd

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.

Start etcd

at the command line

etcd

how to start etcd may differ depending on your setup

Installing etseed

Install etseed

install.packages("etseed")

Development version

install.packages("devtools")
devtools::install_github("ropensci/etseed")
library("etseed")

Make a client

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.

Get version

client$version()

Create a directory

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)

Create a key

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

Update a key

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")

Create in-order keys

client$create_inorder("/queue", "thing1")
client$create_inorder("/queue", "thing2")
client$create_inorder("/queue", "thing3")

List keys

client$keys()

List a key

client$key("/mykey")

Meta

ropensci_footer



ropensci/etseed documentation built on May 18, 2022, 9:54 a.m.