Skip to content
This repository

Collection of functions 4 R and CouchDB interaction

branch: master

Merge branch 'master' of gitproxy:wactbprot/R4CouchDB

Conflicts:
	README.md

	modified:   R4CouchDB/DESCRIPTION
	new file:   R4CouchDB/LICENSE
	modified:   R4CouchDB/NAMESPACE
	modified:   R4CouchDB/R/cdbAddAttachment.R
	modified:   R4CouchDB/R/cdbAddDoc.R
	modified:   R4CouchDB/R/cdbDeleteDoc.R
	modified:   R4CouchDB/R/cdbGetConfig.R
	modified:   R4CouchDB/R/cdbGetDoc.R
	modified:   R4CouchDB/R/cdbGetUuid.R
	modified:   R4CouchDB/R/cdbGetUuidS.R
	modified:   R4CouchDB/R/cdbGetView.R
	modified:   R4CouchDB/R/cdbIni.R
	modified:   R4CouchDB/R/cdbListDB.R
	modified:   R4CouchDB/R/cdbMakeDB.R
	modified:   R4CouchDB/R/cdbRemoveDB.R
	modified:   R4CouchDB/R/cdbUpdateDoc.R
	modified:   R4CouchDB/man/cdbAddAttachment.Rd
	modified:   R4CouchDB/man/cdbAddDoc.Rd
	modified:   R4CouchDB/man/cdbGetConfig.Rd
	modified:   R4CouchDB/man/cdbGetDoc.Rd
	modified:   R4CouchDB/man/cdbGetUuid.Rd
	modified:   R4CouchDB/man/cdbGetUuidS.Rd
	modified:   R4CouchDB/man/cdbIni.Rd
	modified:   R4CouchDB/man/cdbListDB.Rd
	modified:   R4CouchDB/man/cdbMakeDB.Rd
	modified:   R4CouchDB/man/cdbRemoveDB.Rd
	modified:   R4CouchDB/man/cdbUpdateDoc.Rd
	deleted:    R4CouchDB_0.2.4.tar.gz
	deleted:    R4CouchDB_0.2.5.tar.gz
	new file:   R4CouchDB_0.3.3.tar.gz
	new file:   R4CouchDB_0.4.tar.gz
	modified:   README.md
	new file:   example/3dplot.pdf
	modified:   example/test-session.R
latest commit 7dd1cf6678
wactbprot authored
Octocat-spinner-32 R4CouchDB notrun examples, rm trailing whitspaces January 01, 2014
Octocat-spinner-32 example notrun examples, rm trailing whitspaces January 01, 2014
Octocat-spinner-32 R4CouchDB_0.3.2.tar.gz 0.3.2 October 30, 2013
Octocat-spinner-32 R4CouchDB_0.3.3.tar.gz add digits param for toJSON conversion see #39 December 30, 2013
Octocat-spinner-32 R4CouchDB_0.3.tar.gz 0.3.1 September 15, 2013
Octocat-spinner-32 R4CouchDB_0.4.tar.gz notrun examples, rm trailing whitspaces January 01, 2014
Octocat-spinner-32 README.md Merge branch 'master' of gitproxy:wactbprot/R4CouchDB January 17, 2014
README.md
         __ _  _     ___                 _        ___  ___ 
        /__\ || |   / __\___  _   _  ___| |__    /   \/ __\
       / \// || |_ / /  / _ \| | | |/ __| '_ \  / /\ /__\//
      / _  \__   _/ /__| (_) | |_| | (__| | | |/ /_// \/  \
      \/ \_/  |_| \____/\___/ \__,_|\___|_| |_/___,'\_____/

A Collection of R functions for CouchDB access

The R4CouchDB package provides a collection of functions for basic database and document management operations such as add and delete.

Every cdbFunction() gets and returns a list() containing the complete connection set up and the data. With the command

cdb <- cdbIni()

such a list() can be generated. It contains some default values e.g. the

cdb$serverName
[1] "localhost"

or

cdb$digits
[1] 7

Note: Check out sofa, from @recology_ another R package to interact with CouchDB.

Getting started

  install.packages("R4CouchDB")

(please be aware of the fact that beside R-base-devel must be installed Rcurl needs libcurl-devel)

  • an further way for those who have devtools installed is
         library(devtools)
         install_github('R4CouchDB', 'wactbprot', subdir = 'R4CouchDB')

(see e.g. http://www.inside-r.org/packages/cran/devtools/docs/install_github)

  • open R shell and load library with:
         library(R4CouchDB)
  • generate a connection object (a simple list()) with:
         foo <- cdbIni()
  • play around with foo
         foo$queryParam <- "count=10"
         cdbGetUuidS(foo)$res
  • see test session in the example folder

  • get angry and write a issue

Problems

untar

If you get somenthing like this:

        untar2(tarfile, files, list, exdir) : unsupported entry type ‘x’

on installation you can try

       export R_INSTALL_TAR=tar

and than

       R CMD INSTALL R4CouchDB_latest_

\r

In the function cdbIni() I added with 0.1.2 the lines:

       cdb$toJSON <- function(lst){
         jsn <- toJSON(lst,
                collapse = "",
                digits = digits)
         jsn <- gsub("\\r","\\\\r",jsn)
         return(jsn)
       }

The point is: one can have a

       {"a":"\r"}

in the database but one can not send it back this way. A \r is here replaced by \\r resulting in \r in the database. The gsub() function behaves like this:

       > gsub("\\r","\\\\r","\r")
       [1] "\\r"
       > gsub("\\r","\\\\r","\\r")
       [1] "\\r"
       > gsub("\\r","\\\\r","\\\r")
       [1] "\\\\r"
       > gsub("\\r","\\\\r","\\\\r")
       [1] "\\\\r"

I'm not happy with this but have no better solution for the moment.

digits

Numbers are converted to JSON with 7 digits by default.

      > cdbIni()$digits
      [1] 7

Adjust this to your needs by:

      cdb        <- cdbIni()
      cdb$digits <- 13
Something went wrong with that request. Please try again.