Permalink
Browse files

megre with >>doc_wo_R<< branch

  • Loading branch information...
2 parents f31ac61 + 333d578 commit 2da1665d985f6943c1e28f7b70b28304307c6459 @wactbprot committed Oct 12, 2012
@@ -1,3 +1,47 @@
+#' Add attachments
+#'
+#' This function adds attachments to a doc.
+#'
+#' The function uses a simple call to \code{strsplit(fileName, ".")} and takes
+#' the last entry of the resulting vector as the \code{Content-Type} in the
+#' \code{httpheader}.
+#'
+#' @usage cdbAddAttachment(cdb)
+#' @param cdb The list \code{cdb} has to contain
+#' \code{cdb$fileName},\code{cdb$serverName}, \code{cdb$DBName} and a
+#' \code{cdb$id}.
+#' @return \item{cdb}{The result is stored in \code{cdb$res} }
+#' @author wactbprot
+#' @export
+#' @keywords misc
+#' @examples
+#'
+#'
+#'# 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")
+#'
+#' cdb <- cdbIni()
+#' cdb$serverName <- "localhost"
+#'
+#' cdb$DBName <- "r4couchdb" ## should already exist
+#' cdb$fileName <- paste("../",cdb$DBName,".test.png", sep="")
+#' cdb$dataList <- list(data=list(x=x,y=y,z=z),
+#' date=cdb$date)
+#' cdb <- cdbAddDoc(cdb)
+#'
+#' png(filename=cdb$fileName)
+#' persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue")
+#' dev.off()
+#'
+#' ## finaly the reason why we are here:
+#' cdb <- cdbAddAttachment(cdb)
+#'
+
cdbAddAttachment <- function( cdb){
fname <- deparse(match.call()[[1]])
View
@@ -1,3 +1,32 @@
+#' Generates a new document
+#'
+#' This function adds a new document to an already existing database
+#'
+#' This function is called addDoc (which means add a new document). Therefore
+#' the \code{cdb$id} is requested using \code{cdbGetUuid()} for every document
+#' to add if no \code{cdb$id} is provided. If a \code{cdb$id} is provided the
+#' function fails when a document with the given id already exists. In this
+#' case one should use \code{cdbUpdateDoc()}. Since version v0.6 the function
+#' writes the \code{_rev} and \code{_id} key to the top level of
+#' \code{cdb$dataList}.
+#'
+#' @usage cdbAddDoc(cdb)
+#' @param cdb The list \code{cdb} only has to contain a \code{cdb$dataList}
+#' which is not an empty \code{list()}.
+#' @return \item{cdb}{The couchdb response is stored in \code{cdb$res} }
+#' @author wactbprot
+#' @export
+#' @seealso \code{cdbGetDoc()}
+#' @keywords misc
+#' @examples
+#'
+#' ccc <- cdbIni()
+#' ccc$DBName <- "r4couchdb" ## should already exist
+#' ccc$dataList <- list(normalDistRand = rnorm(20))
+#'
+#' cdbAddDoc(ccc)$res
+#'
+
cdbAddDoc <- function( cdb){
fname <- deparse(match.call()[[1]])
View
@@ -1,3 +1,26 @@
+#' Deletes a document from a database
+#'
+#' With a given \code{cdb$id} this function sends a http \code{"DELETE"}
+#' request to the url \code{.../cdb$id?rev=cdb$rev}.
+#'
+#'
+#' @usage cdbDeleteDoc(cdb)
+#' @param cdb Beside \code{cdb$serverName}, \code{cdb$port} and
+#' \code{cdb$DBName} the \code{cdb$id} must be given. R errors are reported in
+#' \code{cdb$errors}
+#' @return
+#'
+#' \item{cdb }{The result of the delete request is stored in
+#' \code{cdb$res}(whatever this means). }
+#' @author wactbprot
+#' @export
+#' @seealso \code{cdbAddDoc()}
+#' @references
+#'
+#' \url{ http://couchdb.apache.org/ } \url{ http://www.omegahat.org/ }
+#' @keywords misc
+#'
+
cdbDeleteDoc <- function( cdb ){
fname <- deparse(match.call()[[1]])
View
@@ -1,3 +1,23 @@
+#' Request couchdb config
+#'
+#' Function provides access to the \code{_config} api end point
+#'
+#'
+#' @param cdb Only the connection settings \code{cdb$port} and
+#' \code{cdb$serverName} is needed.
+#' @return
+#'
+#' \item{cdb }{The result of the request is stored in \code{cdb$re} after
+#' converting the answer into a list using \code{fromJSON()}. }
+#' @author wactbprot
+#' @export
+#' @seealso \code{cdbMakeDB}
+#' @references
+#'
+#' \url{ http://www.omegahat.org/RCurl/ } \url{
+#' http://www.omegahat.org/RJSONIO/ } \url{ http://couchdb.apache.org/ }
+#' @keywords misc
+
cdbGetConfig <- function(cdb){
fname <- deparse(match.call()[[1]])
View
@@ -1,3 +1,35 @@
+#' Get a doc from CouchDB
+#'
+#' With a given \code{cdb$id} this function requests the document.
+#'
+#'
+#' @usage cdbGetDoc(cdb)
+#' @param cdb Beside \code{cdb$serverName}, \code{cdb$port} and
+#' \code{cdb$DBName} the \code{cdb$id} must be given. R errors are reported
+#'
+#' in cdb$errors
+#' @return
+#'
+#' \item{cdb }{The result of the request is stored in \code{cdb$res} after
+#' converting the answer into a list using \code{fromJSON()}. If a list entry
+#' needed in \code{cdb} is not provided \code{cdb$error} gives some
+#' information.
+#'
+#' }
+#' @author wactbprot
+#' @export
+#' @seealso \code{cdbAddDoc()}
+#' @references
+#'
+#' \url{ http://couchdb.apache.org/ } \url{ http://www.omegahat.org/ }
+#' @keywords misc
+#' @examples
+#'
+#' ccc <- cdbIni()
+#' ccc$DBName <- "r4couchdb" ## should already exist
+#' ccc$dataList <- list(normalDistRand = rnorm(20))
+#' ccc <- cdbAddDoc(ccc)
+
cdbGetDoc <- function(cdb){
fname <- deparse(match.call()[[1]])
View
@@ -1,3 +1,29 @@
+#' Receive list results from CouchDB
+#'
+#' The function provides accesses to CouchDB lists.
+#'
+#' Query params e.g. \code{"reduce=false"} or \code{"group_level=1"} can be
+#' provided in \code{cdb$queryParam} By now multible params must be given in
+#' one string e.g. \code{"a=b&c=d&e=f"}.
+#'
+#' @usage cdbGetList(cdb)
+#' @param cdb Beside the connection details (\code{cdb$port},\code{cdb$DAName}
+#' ...) the \code{cdb$design} \code{cdb$view} and \code{cdb$list} is needed.
+#' @return
+#'
+#' \item{cdb }{The result of the request is stored in cdb$res after converting
+#' the json answer into a list using fromJSON(). If a needed cdb (design, list,
+#' view, ...) entry was not provided cdb$error says something about the R side.
+#'
+#' }
+#' @author wactbprot
+#' @export
+#' @references \url{ http://www.omegahat.org/RCurl } \url{
+#' http://www.omegahat.org/RJSONIO } \url{ http://couchdb.apache.org } \url{
+#' http://www.omegahat.org/RJavaScript }
+#' @keywords misc
+#'
+
cdbGetList <- function( cdb ){
fname <- deparse(match.call()[[1]])
@@ -32,15 +58,3 @@ cdbGetList <- function( cdb ){
stop( cdb$error )
}
}
-
-
-
-
-
-
-
-
-
-
-
-
View
@@ -1,3 +1,24 @@
+#' Function for request one id
+#'
+#' Function returns a 128bit uuid requested from CouchDB
+#'
+#' Simple CouchDB API end point to http://serverName:port/_uuids.
+#'
+#' @param cdb Only the connection settings \code{cdb$port} and
+#' \code{cdb$serverName} is needed.
+#' @return
+#'
+#' \item{cdb }{The result of the request is stored in \code{cdb$id} after
+#' converting the answer into a list using \code{fromJSON()}.}
+#' @author wactbprot
+#' @export
+#' @seealso \code{cdbMakeDB}
+#' @references
+#'
+#' \url{ http://www.omegahat.org/RCurl/ } \url{
+#' http://www.omegahat.org/RJSONIO/ } \url{ http://couchdb.apache.org/ }
+#' @keywords misc
+
cdbGetUuid <- function(cdb){
fname <- deparse(match.call()[[1]])
View
@@ -1,3 +1,33 @@
+#' Function for request a number of ids
+#'
+#' Function returns a 128bit uuid requested from CouchDB
+#'
+#' Simple CouchDB API end point to http://serverName:port/_uuids. The number N
+#' of ids received from a CouchDB can be set by \code{cdb$queryParam <-
+#' paste("count=", N, sep="")}. The function writes to cdb$res (in opposite to
+#' \code{cdbGetUuid()} whitch writes to \code{cdb$id})
+#'
+#' @param cdb Only the connection settings \code{cdb$port} and
+#' \code{cdb$serverName} is needed.
+#' @return
+#'
+#' \item{cdb }{The result of the request is stored in \code{cdb$res} after
+#' converting the answer into a list using \code{fromJSON()}. }
+#' @author wactbprot
+#' @export
+#' @seealso \code{cdbMakeDB}
+#' @references
+#'
+#' \url{ http://www.omegahat.org/RCurl/ } \url{
+#' http://www.omegahat.org/RJSONIO/ } \url{ http://couchdb.apache.org/ }
+#' @keywords misc
+#' @examples
+#'
+#' ccc <- cdbIni()
+#' ccc$queryParam <- "count=10"
+#' cdbGetUuidS(ccc)$res
+#'
+
cdbGetUuidS <- function(cdb){
fname <- deparse(match.call()[[1]])
View
@@ -1,3 +1,32 @@
+#' Receive view results from CouchDB
+#'
+#' The function provides accesses to CouchDB views.
+#'
+#' Query params e.g. \code{"reduce=false"} or \code{"group_level=1"} can be
+#' provided in \code{cdb$queryParam}
+#'
+#' @usage cdbGetView(cdb)
+#' @param cdb Beside the connection details (\code{cdb$port},\code{cdb$DAName}
+#' ...) the \code{cdb$design} and \code{cdb$view} is needed.
+#' @return
+#'
+#' \item{cdb }{The result of the request is stored in cdb$res after converting
+#' the json answer into a list using fromJSON(). If a needed cdb list entry was
+#' not provided cdb$error says something about the R side
+#'
+#' }
+#' @note For the moment only one \code{cdb$queryParam} is possible. In the
+#' future maybe Duncans \code{RJavaScript} package can be used to generate
+#' views without leaving R.
+#' @author wactbprot
+#' @export
+#' @references
+#'
+#' \url{ http://www.omegahat.org/RCurl/ } \url{
+#' http://www.omegahat.org/RJSONIO/ } \url{ http://couchdb.apache.org/ } \url{
+#' http://www.omegahat.org/RJavaScript/ }
+#' @keywords misc
+
cdbGetView <- function( cdb ){
fname <- deparse(match.call()[[1]])
View
@@ -1,3 +1,20 @@
+#' Ini function
+#'
+#' Function returns a list with some default settings and often used functions
+#' such as \code{cdb$baseUrl}.
+#'
+#' The list: \code{ cdb <- list(serverName = "localhost", ... )} is returned if
+#' the packages \code{library(RCurl)} and \code{library(RJSONIO)} are
+#' successfully loaded.
+#'
+#' @usage cdbIni(serverName="localhost",port="5984",dbname="")
+#' @return
+#'
+#' \item{cdb}{see details for the default settings of this function }
+#' @author wactbprot
+#' @export
+#' @keywords misc
+
cdbIni <- function(serverName="localhost",port="5984",dbname=""){
## http://www.omegahat.org/RJSONIO/
## thanx to Duncan Temple Lang
View
@@ -1,3 +1,26 @@
+#' Returns all databases on the server
+#'
+#' Gives a list of all databases available at \code{cdb$serverName}.
+#'
+#' The function uses the CouchDB API end point:
+#' \url{http://localhost:5984/_all_dbs}
+#'
+#' @usage cdbListDB(cdb)
+#' @param cdb Only the connection settings \code{cdb$port} and
+#' \code{cdb$serverName} is needed.
+#' @return
+#'
+#' \item{cdb }{The result of the request is stored in cdb$res after converting
+#' the json answer into a list using \code{cdb$fromJSON()}.}
+#' @author wactbprot
+#' @export
+#' @seealso \code{cdbMakeDB}
+#' @references
+#'
+#' \url{ http://www.omegahat.org/RCurl/ } \url{
+#' http://www.omegahat.org/RJSONIO/ } \url{ http://couchdb.apache.org/ }
+#' @keywords misc
+
cdbListDB <- function(cdb){
fname <- deparse(match.call()[[1]])
View
@@ -1,3 +1,25 @@
+#' Creates a new database
+#'
+#' The name of the new database is taken from \code{cdb$newDBName}.
+#'
+#' The work is done by \code{getURL()} from Duncans RCurl package.
+#'
+#' After creating the new database the function makes the shortcut
+#' \code{cdb$DBName <- cdb$newDBName} so that further operations happen on the
+#' new created database. Finaly \code{cdb$newDBName <- ""}.
+#'
+#' @usage cdbMakeDB(cdb)
+#' @param cdb The \code{cdb} have to provide \code{cdb$serverName},
+#' \code{cdb$port} and \code{cdb$newDBName}
+#' @return \item{cdb}{The CouchDB answer is stored in \code{cdb$res}. Any
+#' problems on the R side are reported in \code{cdb$error} }
+#' @note The convention for database naming should be implemented.
+#' @author wactbprot
+#' @export
+#' @seealso \code{cdbUpdateDoc}
+#' @references \url{ http://couchdb.apache.org/ }
+#' @keywords misc
+
cdbMakeDB <- function(cdb){
fname <- deparse(match.call()[[1]])
@@ -22,4 +44,3 @@ cdbMakeDB <- function(cdb){
stop(cdb$error)
}
}
-
Oops, something went wrong.

0 comments on commit 2da1665

Please sign in to comment.