Clients
R4CouchDB
https://github.com/wactbprot/R4CouchDB A R convenience layer for CouchDB. R4CouchDB unites http://www.omegahat.org/RCurl and http://www.omegahat.org/RJSONIO and implements a part of the CouchDB API.
sofa
https://github.com/sckott/sofa An easy interface to CouchDB from R. sofa uses https://github.com/hadley/httr and http://plyr.had.co.nz/
h3. Clients
h5. R4CouchDB
https://github.com/wactbprot/R4CouchDB
h6. Description
A R convenience layer for CouchDB. R4CouchDB unites http://www.omegahat.org/RCurl and http://www.omegahat.org/RJSONIO and implements a part of the CouchDB API. h6. Example
h.6 Installation
R4CouchDB is part of the cran cosmos so one can say
R> install.packages("R4CouchDB")
h.6 Example
The example below presumes a running CouchDB on http://localhost:5984. First load the R4CouchDB as usual
library("R4CouchDB")
then generate the connection or interface list (here stored in the variable cdb) by
R> cdb <- cdbIni()
cdb assumes some defaults such as
R> cdb$serverName [1] "localhost"
and
R> cdb$port [1] "5984"
Now straight forward: we make a database on http://localhost:5984/r-example, load some fancy volcano data, and write the date (plus some demo info) to a new database document:
R> cdb$newDBName <- "r-example" R> cdb <- cdbMakeDB(cdb) R> data(volcano) R> rdoc <- list(date = date(), data = volcano, dim = dim(volcano)) R> cdb$dataList <- rdoc R> res <- cdbAddDoc(cdb)$res R> res $ok [1] TRUE
$id [1] "26659bf9e39fb9ad6278325963643246"
$rev [1] "1-44e4052a2ef00a8574cad2210e1cfc8e"
We now make a plot of the volcano with the data from the database. At first we get back the data:
cdb$id <- res$id cdoc <- cdbGetDoc(cdb)$res
we regenerate the volcano matrix from this (cdoc) list:
mat <- matrix(data = t(unlist( cdoc$data )),
nrow = cdoc$dim[[2]],
ncol = cdoc$dim[[1]])
And here we are:
R> png("r-example.png") R> persp(mat, theta = 120, phi = 30, col = "green3", shade = 0.75 ) R> dev.off()
h5. sofa
https://github.com/sckott/sofa
An easy interface to CouchDB from R. sofa uses https://github.com/hadley/httr and http://plyr.had.co.nz/
h6. Installation
sofa can be installed from github using devtools:
R> install.packages("devtools") R> library(devtools) R> install_github("sofa", "sckott")
h6. Example
library('sofa')
sofa_ping()
$couchdb
[1] "Welcome"
$uuid
[1] "2c10f0c6d9bd17205b692ae93cd4cf1d"
$version
[1] "1.5.0"
$vendor
$vendor$version
[1] "1.5.0-1"
$vendor$name
[1] "Homebrew"
sofa_createdb(dbname='sofadb')
$ok
[1] TRUE
sofa_listdbs()
[1] "_replicator" "_users" "cachecall" "mran" "mydb" "sofadb"
doc1 <- '{"name":"my_favorite_beer","beer":"IPA"}'
sofa_writedoc(dbname="sofadb", doc=doc1, docid="beer")
$ok
[1] TRUE
$id
[1] "beer"
$rev
[1] "1-449148505e2ac94f57d0aa2e68a50b0d"
sofa_getdoc(dbname="sofadb", docid="beer")
$`_id`
[1] "beer"
$`_rev`
[1] "1-449148505e2ac94f57d0aa2e68a50b0d"
$name
[1] "my_favorite_beer"
$beer
[1] "IPA"
sofa_changes(dbname="sofadb")
$results
$results[[1]]
$results[[1]]$seq
[1] 1
$results[[1]]$id
[1] "beer"
$results[[1]]$changes
$results[[1]]$changes[[1]]
$results[[1]]$changes[[1]]$rev
[1] "1-449148505e2ac94f57d0aa2e68a50b0d"
$last_seq
[1] 1