Git Product home page Git Product logo

sofa's Introduction

sofa

CRAN status Project Status: Active – The project has reached a stable, usable state and is being actively developed. R-check codecov.io rstudio mirror downloads

An easy interface to CouchDB from R

sofa docs: https://docs.ropensci.org/sofa/

CouchDB versions

sofa works with CouchDB v2 and v3. See the builds for checks on various CouchDB versions.

CouchDB Info

Connect to CouchDB

This may be starting it on your terminal/shell

couchdb

Or opening the CouchDB app on your machine, or running it in Docker. Whatever it is, start it up.

Install sofa

From CRAN

install.packages("sofa")

Development version from GitHub

remotes::install_github("ropensci/sofa")

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:

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.

x <- Cushion$new()

Ping the server

x$ping()

Nice, it’s working.

More

See the docs https://docs.ropensci.org/sofa/ for more.

Meta

  • Please report any issues or bugs.
  • 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. By participating in this project you agree to abide by its terms.

ropensci_footer

sofa's People

Contributors

eduardszoecs avatar maelle avatar michellymenezes avatar patperu avatar sckott avatar yaoxiangli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sofa's Issues

Extra brackets for nested array

'sofa' seems to write extra brackets for nested arrays. I'm note sure, but I think they are not necessary.

library('sofa')
library('jsonlite')

options(stringsAsFactors = FALSE)

# Example from jsonlite / json-mapping.pdf
x <- data.frame(author = c("Homer", "Virgil", "Jeroen"))
x$poems <- list(c("Iliad", "Odyssey"), c("Eclogues", "Georgics", "Aeneid"), vector());
names(x)

toJSON(x[1, ], pretty = TRUE)

# [
#    {
#        "author": "Homer",
#        "poems": [
#            "Iliad",
#            "Odyssey"
#        ]
#    }
# ]

# local CouchDB running?
# yes, WIN64
ping()
# $version
# [1] "1.6.1"

db_create(dbname = 'test')

for (i in 1:nrow(x)) {
  doc_create(dbname = 'test', doc = as.list(x[i,]))
}

# Copy via Futon

# {
#   "_id": "f0b286aebef7887771711ad921004cbc",
#   "_rev": "1-200f4b3b4640a536047b7147bb409206",
#   "author": "Homer",
#   "poems": [
#       [              <---------- extra bracket
#           "Iliad",
#           "Odyssey"
#       ]              <---------- extra bracket
#   ]
# }
# POST via 'curl'
curl -X GET http://127.0.0.1:5984/test/f0b286aebef7887771711ad92100adc1
{"_id":"f0b286aebef7887771711ad92100adc1",
    "_rev":"1-38e34a2b327b4c26458efa6b81fca866",
        "author":"Virgil",
           "poems":["Eclogues","Georgics","Aeneid"]}

# POST via 'sofa'
curl -X GET http://127.0.0.1:5984/test/f0b286aebef7887771711ad921008d1a
{"_id":"f0b286aebef7887771711ad921008d1a",
     "_rev":"1-6ced453d63a2535b44e124bdb3bb01d7",
         "author":"Virgil",
            "poems":[["Eclogues","Georgics","Aeneid"]]}

Please make `delifexists = TRUE` possible, even if the db doesn't exist

Hello Scott,

if I call db_create with delifexists = TRUE and the db does not exist, I'm getting an error.

library('sofa') # 0.1.8.9400

# db 'foo' doesn't exist
grep("foo", db_list(), value = TRUE)
# character(0)

db_create(cushion = "localhost", dbname = "foo", delifexists = TRUE)
# Error in sofa_DELETE(sprintf("http://127.0.0.1:%s/%s", cushion$port, dbname),  : 
#   Not Found (HTTP 404).

I would like to create the db foo every time I run the script. Right now I have to make the first function call with the default (delifexists = FALSE).

Best
Patrick

design_search needs POST support to use key feature

Get "Error: (400) - invalid UTF-8 JSON" when trying to specify a key to retrieve from a view.

Couch documentation 10.5.4 indicates:
Unlike GET /{db}/_design/{ddoc}/_view/{view} for accessing views, the POST method supports the specification of explicit keys to be retrieved from the view results. The remainder of the POST view functionality is identical to the GET /{db}/_design/{ddoc}/_view/{view} API.

Any chance of getting an updated design_search with POST support to handle the super-set of features?

A number of routes don't seem to work in CouchDB v2

  • _stats (removed from couch, so remove from sofa)
  • _log (removed from couch, didn't have a fxn in sofa anyway)
  • _config (removed from couch, didn't have a fxn in sofa anyway)
  • _active_tasks (nevermind, does work)
  • _session (nevermind, does work)

and probably more

Whereas in Couchdb v1.6, all these work fine

anyone have ideas? Is it possible i installed v2 wrong? I installed the app from http://couchdb.apache.org/#download and start it from /Applications

fix vignette

e..g,. devtools::install_github("rbison", "ropensci")

look for any other problems

try sofa?

We're nearly ready to send to CRAN I think. But I want to make sure I haven't made any stupid mistakes, and we've accounted for most everything. And user interface is nice, etc.

please do try if you have time, and let me know of any feedback.

note that some function names have changed as the new names I thought made more sense. Sorry about fxn names changing, but its not on CRAN yet, so this is the time to make big changes.

Install: devtools::install_github("ropensci/sofa")


@katsel @patperu @andrewcstewart

Error: (400) - Referer header required

Getting this with 1.6.1.

query all in one json blob

> db_explain(z, dbname = "omdb", query = '{
+            "selector": {
+            "_id": {
+            "$gt": null
+            }
+            }
+            }')
Error: (400) - Referer header required.

Storing and Loading document attachments

I've been playing around with how to do this within R and was wondering what your thoughts are. I see you a getattach and doc_attach functions, though doc_attach isn't implemented yet and I can't get getattach to work for me. I get the following error, if curious:

getattach(dbname = "mydb", docid = "a99569a30658181ff9e3e7340d00e2fc", attname = "foobar.Rds")
Error in parseJSON(txt) : lexical error: invalid char in json text.
                                       �
                     (right here) ------^

I've also been trying to directly fetch an attachment from a couchdb url into my current R session (an RDS file) without any luck.

readRDS(url("http://atlas.veracyte.lan:5984/uci/a99569a30658181ff9e3e7340d00e2fc/mag7.eset.rds",open = "rb"))
Error: unknown input format

Wondering if you have any insight on either of those two cases.

Retain value type

Seems that data classes aren't being retained when put into couchdb, check this...and fix if true

"Error: length(url) == 1 is not TRUE"

Hi there. I might be setting up the cushion wrong, but I keep getting the following error while trying to do a db_delete or create.

cushion(name = 'localhost', type="localhost")
db_delete(cushion = 'localhost', dbname = 'allegro')

Error: length(url) == 1 is not TRUE

Numeric values are stored as strings

Hello Scott,

I just imported the 'iris' dataset in a local CouchDB via 'bulk_create'.
But all values are stored as strings even the numeric ones.
Same happens with 'doc_create'

Best
Patrick

library('sofa')
cushion(name = 'local', type = "localhost")
db_create("local", dbname = 'xiris')
bulk_create(iris, "local", dbname = "xiris")
devtools::session_info()
Session info -----------------------------------------------------------------------------------------------------------------------
 setting  value                                      
 version  R version 3.2.2 Patched (2015-08-21 r69156)
 system   x86_64, mingw32                            
 ui       Rgui                                       
 language (EN)                                       
 collate  German_Germany.1252                        
 tz       Europe/Berlin                              
 date     2015-09-17                                 

Packages ---------------------------------------------------------------------------------------------------------------------------
 package    * version  date       source                        
 curl         0.9.3    2015-08-25 CRAN (R 3.2.2)                
 devtools     1.9.0    2015-08-23 local                         
 digest       0.6.8    2014-12-31 CRAN (R 3.2.2)                
 httr         1.0.0    2015-06-25 CRAN (R 3.2.2)                
 jsonlite     0.9.17   2015-09-06 CRAN (R 3.2.2)                
 magrittr     1.5      2014-11-22 CRAN (R 3.2.2)                
 memoise      0.2.1    2014-04-22 CRAN (R 3.2.2)                
 plyr         1.8.3    2015-06-12 CRAN (R 3.2.2)                
 R6           2.1.1    2015-08-19 CRAN (R 3.2.2)                
 Rcpp         0.12.1   2015-09-10 CRAN (R 3.2.2)                
 rstudioapi   0.3.1    2015-04-07 CRAN (R 3.2.2)                
 sofa       * 0.1.7.99 2015-09-17 Github (ropensci/sofa@200befe)
 stringi      0.5-5    2015-06-29 CRAN (R 3.2.2)                
 stringr      1.0.0    2015-04-30 CRAN (R 3.2.2)

Question on how get_view works

I'm somewhat confused by the function definition for get_view().

view_get(cushion = "localhost", dbname, design_name, as = "json", ...)

It looks like in your examples that you're passing the name of the view to the design_name parameter, but shouldn't there be separate design_name and view_name parameters?

other /db routes to add later

  • /db/_compact/design-doc
  • /db/_ensure_full_commit
  • /db/_view_cleanup
  • /db/_security
  • /db/_purge
  • /db/_missing_revs
  • /db/_revs_diff
  • /db/_revs_limit

Not able to connect to Cloudant with an API-Key

Hello Scott,

I always use my username and password to connect to a Cloudant Database.
Now I would like to give someone else read/write access to a selected DB. So I generated an API Key/Secret for this DB and tried to connect with this combination. But I got an error, see script:

library('sofa')

# with my username and password - it works!
user_name <- "fake"
user_pwd  <- "notreal"

cushion('cloudant', user = user_name, pwd= user_pwd, type="cloudant")
ping('cloudant')
# $couchdb
# [1] "Welcome"
# $version
# [1] "1.0.2"
# $cloudant_build
# [1] "2530"

# With the API-Key (fictional) for the Sample-DB 'ariaarpa' I got this error message:
api_name <- "rofetog"
api_pwd  <- "a638ce138ec"

cushion('api_cloudant', user=api_name, pwd=api_pwd, type="cloudant")
ping('api_cloudant')
# Error: lexical error: invalid char in json text.
#                                       <html><body><h1>503 Service Una
#                     (right here) ------^ 

Thanks for any help!
Patrick

view_search

Thanks once again for this package. I have moved from 1.6.1 Now getting this error.

res <- view_search(x, dbname='omdb', design='view2')
Error: could not find function "view_search"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.