forked from ropensci/sofa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
160 lines (113 loc) · 3.94 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
sofa
====
```{r, echo=FALSE}
knitr::opts_chunk$set(
collapse=TRUE,
comment="#>",
warning=FALSE,
message=FALSE
)
```
<pre>
_ _ _ _ _ _ _ _ _ _ _
/| |\
/ |_ _ _ _ _ _ _ _ _ _| \
\ / \/
\ ___________________ /
</pre>
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![cran checks](https://cranchecks.info/badges/worst/sofa)](https://cranchecks.info/pkgs/sofa)
[![Build Status](https://travis-ci.org/ropensci/sofa.svg?branch=master)](https://travis-ci.org/ropensci/sofa)
[![codecov.io](https://codecov.io/github/ropensci/sofa/coverage.svg?branch=master)](https://codecov.io/github/ropensci/sofa?branch=master)
[![rstudio mirror downloads](https://cranlogs.r-pkg.org/badges/sofa?color=ff69b4)](https://github.com/metacran/cranlogs.app)
[![cran version](http://www.r-pkg.org/badges/version/sofa)](https://cran.r-project.org/package=sofa)
__An easy interface to CouchDB from R__
Note: Check out [*R4couchdb*](https://github.com/wactbprot/R4CouchDB), another R
package to interact with CouchDB.
## CouchDB versions
`sofa` is built targeting CouchDB v2 or greater.
## CouchDB Info
* Docs: <http://docs.couchdb.org/en/latest/index.html>
* Installation: <http://docs.couchdb.org/en/latest/install/index.html>
## Connect to CouchDB
This may be starting it on your terminal/shell
```sh
couchdb
```
Or opening the CouchDB app on your machine, or running it in Docker. Whatever it
is, start it up.
You can interact with your CouchDB databases as well in your browser. Navigate to http://localhost:5984/_utils
## Install sofa
From CRAN
```{r eval=FALSE}
install.packages("sofa")
```
Development version from GitHub
```{r eval=FALSE}
devtools::install_github("ropensci/sofa")
```
```{r}
library('sofa')
```
## Cushions
Cushions? What? Since it's couch we gotta use `cushions` somehow. `cushions` are a
connection class containing all connection info to a CouchDB instance.
See `?Cushion` for help.
As an example, connecting to a Cloudant couch:
```{r eval=FALSE}
z <- Cushion$new(
host = "stuff.cloudant.com",
transport = 'https',
port = NULL,
user = 'foobar',
pwd = 'things'
)
```
Break down of parameters:
* `host`: the base url, without the transport (`http`/`https`)
* `path`: context path that is appended to the end of the url
* `transport`: `http` or `https`
* `port`: The port to connect to. Default: 5984. For Cloudant, have to set to `NULL`
* `user`: User name for the service.
* `pwd`: Password for the service, if any.
* `headers`: headers to pass in all requests
If you call `Cushion$new()` with no arguments you get a cushion set up for local
use on your machine, with all defaults used.
```{r}
x <- Cushion$new()
```
## Ping the server
```{r}
x$ping()
```
Nice, it's working.
## Create a new database, and list available databases
```{r echo=FALSE}
if ("sofadb" %in% db_list(x)) db_delete(x, dbname = 'sofadb')
```
```{r}
db_create(x, dbname = 'sofadb')
```
see if its there now
```{r}
db_list(x)
```
## Create documents
### Write a document WITH a name (uses PUT)
```{r}
doc1 <- '{"name":"sofa","beer":"IPA"}'
doc_create(x, doc1, dbname = "sofadb", docid = "a_beer")
```
### Write a json document WITHOUT a name (uses POST)
```{r}
doc2 <- '{"name":"sofa","icecream":"rocky road"}'
doc_create(x, doc2, dbname = "sofadb")
```
## More docs
See the [vignettes](https://github.com/ropensci/sofa/tree/master/vignettes) for more documentation.
## Meta
* Please [report any issues or bugs](https://github.com/ropensci/sofa/issues).
* License: MIT
* Get citation information for `sofa` in R doing `citation(package = 'sofa')`
* Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.
[![ropensci_footer](http://ropensci.org/public_images/github_footer.png)](http://ropensci.org)