Permalink
Browse files

few docum.

  • Loading branch information...
1 parent 0dab22f commit 8b6bea99e804d703dfa2526f0681a83155bc9364 @wactbprot committed Feb 25, 2013
Showing with 57 additions and 39 deletions.
  1. +25 −13 README.md
  2. +32 −26 example/example.R
View
@@ -1,13 +1,10 @@
-
- _____ _ ) ___ ______ ______
- (, / ) / / (__/_____) /) (, / ) (, / )
- /__ / /___/_ / ___ _ (/ / / /---(
- ) / \_ / / (_)(_(_(__/ )__/___ /_ ) / ____)
- (_/ / (______) (_/___ / (_/ (
-
-
-
-
+<pre>
+ __ _ _ ___ _ ___ ___
+ /__\ || | / __\___ _ _ ___| |__ / \/ __\
+ / \// || |_ / / / _ \| | | |/ __| '_ \ / /\ /__\//
+ / _ \__ _/ /__| (_) | |_| | (__| | | |/ /_// \/ \
+ \/ \_/ |_| \____/\___/ \__,_|\___|_| |_/___,'\_____/
+</pre>
## A Collection of R functions for CouchDB access
@@ -32,9 +29,11 @@ provide a CouchDB. There are some examples below the demo folder.
installed in the same way
* an easier 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:
@@ -96,6 +95,19 @@ In cdbIni I added with 0.1.2 the lines:
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. I'm not happy
+resulting in \r in the database.
+The gsub statement 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.
-
+
+
View
@@ -1,59 +1,65 @@
-##
-## R4CouchDB example session
-##
+#'
+#' R4CouchDB example session
+#'
+#' @author wactbprot
+#' in this file we have no need to
+#' install the R4Couchdb package
srcPath <- "../R4CouchDB/R/"
fn <- list.files(srcPath, pattern="R$")
-
for (k in 1:length(fn)){
- source(paste(srcPath,fn[k],sep=""))
+ source(paste(srcPath, fn[k], sep=""))
}
+#' but we need the RCurl & RJSONIO lib
+library(RCurl)
+library(RJSONIO)
ccc <- cdbIni()
-## here one can do some auth settungs
-## ccc$uname <- "user.name"
-## ccc$pwd <- "pass.word"
+#' here one can do some auth settungs
+#' ccc$uname <- "user.name"
+#' ccc$pwd <- "pass.word"
-## database list please
+#' database list please
ccc <- cdbListDB(ccc)
ccc$res
ccc$queryParam <- "count=10"
-## writes the id now to ccc$res:
+#' writes the id now to ccc$res:
cdbGetUuidS(ccc)$res
-## reset queryParam e.g. for cdbGetView()
+#' reset queryParam e.g. for cdbGetView()
ccc$queryParam <- ""
-## writes the id to ccc$id
+#' writes the id to ccc$id
ccc <- cdbGetUuid(ccc)
ccc$id
-## the paste() with id makes sure that the db don't exist
+#' the paste() with id makes sure that the db don't exist
ccc$newDBName <- paste("r4couchdb_", ccc$id, sep="")
ccc <- cdbMakeDB(ccc)
ccc$res
-## generate some data and add to dataList
+#' generate some data and add to dataList
ccc$dataList <- list(normalDistRand = rnorm(20))
ccc <- cdbAddDoc(ccc)
-## since v0.6 her ccc$dataList
-## contains the _id and _rev key
-## everything ok?
+#' since v0.6 her ccc$dataList
+#' contains the _id and _rev key
+#' everything ok?
cdbGetDoc(ccc)$res
-## try cdbUpdateDoc(ccc)
+#' try cdbUpdateDoc(ccc)
ccc$dataList$Date <- date()
ccc <- cdbUpdateDoc(ccc)
-## make a png (stolen from ?persp)
+#' make a png (stolen from ?persp)
x <- seq(-10, 10, length= 30)
y <- x
f <- function(x,y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }
z <- outer(x, y, f)
+
z[is.na(z)] <- 1
-op <- par(bg = "white")
+op <- par(bg = "white")
ccc$fileName <- paste("../",ccc$DBName,".test.png", sep="")
ccc$dataList <- list(data=list(x=x,y=y,z=z),
date=ccc$date)
@@ -66,11 +72,11 @@ persp(x, y, z,
col = "lightblue")
dev.off()
-## add the plot as attachment to the db
+#' add the plot as attachment to the db
ccc <- cdbAddAttachment(ccc)
-##
-## remove the db when ready
-## ccc$removeDBName <- ccc$newDBName
-## ccc <- cdbRemoveDB(ccc)
-##
+if(FALSE){
+ remove the db when ready
+ ccc$removeDBName <- ccc$newDBName
+ ccc <- cdbRemoveDB(ccc)
+}

0 comments on commit 8b6bea9

Please sign in to comment.