Changeset: 35651576c4c5 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=35651576c4c5
Added Files:
        clients/R/monet.frame/DESCRIPTION
        clients/R/monet.frame/NAMESPACE
        clients/R/monet.frame/NEWS
        clients/R/monet.frame/R/monetframe.R
        clients/R/monet.frame/db.tests/monetframe.test.R
        clients/R/monet.frame/man/aggregatef.Rd
        clients/R/monet.frame/man/as.data.frame.Rd
        clients/R/monet.frame/man/as.list.Rd
        clients/R/monet.frame/man/mf.Rd
        clients/R/monet.frame/man/monet.frame.Rd
        clients/R/monet.frame/man/sample.Rd
        clients/R/monet.frame/man/sd.Rd
        clients/R/monet.frame/man/set.debug.Rd
        clients/R/monet.frame/man/tabulate.Rd
        clients/R/monet.frame/man/tabulate.monet.frame.Rd
        clients/R/monet.frame/man/var.Rd
Removed Files:
        clients/R/MonetDB.R/R/monetframe.R
        clients/R/MonetDB.R/man/aggregatef.Rd
        clients/R/MonetDB.R/man/as.data.frame.Rd
        clients/R/MonetDB.R/man/as.list.Rd
        clients/R/MonetDB.R/man/mf.Rd
        clients/R/MonetDB.R/man/monet.frame.Rd
        clients/R/MonetDB.R/man/sample.Rd
        clients/R/MonetDB.R/man/sd.Rd
        clients/R/MonetDB.R/man/set.debug.Rd
        clients/R/MonetDB.R/man/tabulate.Rd
        clients/R/MonetDB.R/man/tabulate.monet.frame.Rd
        clients/R/MonetDB.R/man/var.Rd
Modified Files:
        clients/R/MonetDB.R/DESCRIPTION
        clients/R/MonetDB.R/NAMESPACE
        clients/R/MonetDB.R/NEWS
        clients/R/MonetDB.R/R/monetdb.R
        clients/R/MonetDB.R/man/MonetDB.R.Rd
Branch: default
Log Message:

R Connector: Moved monet.frame virtual data object into its own R package


diffs (truncated from 3694 to 300 lines):

diff --git a/clients/R/MonetDB.R/DESCRIPTION b/clients/R/MonetDB.R/DESCRIPTION
--- a/clients/R/MonetDB.R/DESCRIPTION
+++ b/clients/R/MonetDB.R/DESCRIPTION
@@ -1,11 +1,11 @@
 Package: MonetDB.R
-Version: 0.8.0
-Date: 2013-10-13
+Version: 0.8.2
+Date: 2013-10-16
 Title: Connect MonetDB to R
 Authors@R: c(person("Hannes Muehleisen", role = c("aut", "cre"),email = 
"han...@cwi.nl"),
        person("Thomas Lumley", role = "ctb"),
        person("Anthony Damico", role = "ctb"))
-Depends: DBI (>= 0.2-5), digest (>= 0.6.0), methods, utils, stats
+Depends: DBI (>= 0.2-5), digest (>= 0.6.0),methods
 Description: Allows to pull data from MonetDB into R
 License: MPL (== 1.1)
 URL: http://monetr.r-forge.r-project.org
diff --git a/clients/R/MonetDB.R/NAMESPACE b/clients/R/MonetDB.R/NAMESPACE
--- a/clients/R/MonetDB.R/NAMESPACE
+++ b/clients/R/MonetDB.R/NAMESPACE
@@ -1,4 +1,4 @@
-import(DBI,utils,stats,digest,methods)
+import(DBI,digest,methods)
 
 # export only driver constructor, everything else is DBI stuff..
 export(MonetDB,MonetR,MonetDBR,MonetDB.R)
@@ -8,78 +8,14 @@ exportMethods(dbSendUpdate,dbSendUpdateA
 export(monetdbGetTransferredBytes)
 export(monetdbRtype)
 
-# monet.frame things, this is an S3 class
-# constructors
-export(monet.frame)
-export(mf)
-export(set.debug)
-
 # shorthand for db connections
 export(mc)
 
-# conversion to native R
-S3method(as.list,monet.frame)
-S3method(as.data.frame,monet.frame)
-S3method(as.vector,monet.frame)
-export(av)
-export(adf)
-
-# inspection
-S3method(str,monet.frame)
-S3method(print,monet.frame)
-S3method(Summary,monet.frame)
-S3method(summary,monet.frame)
-S3method(names,monet.frame)
-S3method(dim,monet.frame)
-S3method(length,monet.frame)
-S3method(na.fail,monet.frame)
-
-# subsetting
-S3method(head,monet.frame)
-S3method(tail,monet.frame)
-S3method("[",monet.frame)
-S3method("$",monet.frame)
-S3method(subset,monet.frame)
-S3method(na.omit,monet.frame)
-S3method(sample, monet.frame)
-S3method(sample, default)
-export(sample)
-
-
-
-# math/stats
-S3method(Ops,monet.frame)
-S3method(Math,monet.frame)
-S3method(mean,monet.frame)
-S3method(sd, monet.frame)
-S3method(sd, default)
-export(sd)
-S3method(var, monet.frame)
-S3method(var, default)
-export(var)
-S3method(quantile,monet.frame)
-S3method(median,monet.frame)
-S3method(aggregate,monet.frame)
-export(aggregatef) # temp!
-
-export(tabulate)
-S3method(tabulate, monet.frame)
-S3method(tabulate, default)
-
-S3method(unique, monet.frame)
-S3method(range, monet.frame)
-
-# reorganization
-S3method(rbind,monet.frame)
-S3method(merge,monet.frame)
-S3method(sort,monet.frame)
-
 # control.R
 export(monetdb.server.setup)
 export(monetdb.server.start)
 export(monetdb.server.stop)
 
-
 useDynLib(MonetDB.R)
 
 
diff --git a/clients/R/MonetDB.R/NEWS b/clients/R/MonetDB.R/NEWS
--- a/clients/R/MonetDB.R/NEWS
+++ b/clients/R/MonetDB.R/NEWS
@@ -1,3 +1,7 @@
+0.8.1
+- fixed bug in dbWriteTable() where VARCHAR(255) was used for character data 
instead of STRING
+- moved monet.frame into separate package
+
 0.8
 - New All-C socket code (Thanks, Windows)
 - new dbConnect() parameter organization (!)
diff --git a/clients/R/MonetDB.R/R/monetdb.R b/clients/R/MonetDB.R/R/monetdb.R
--- a/clients/R/MonetDB.R/R/monetdb.R
+++ b/clients/R/MonetDB.R/R/monetdb.R
@@ -239,13 +239,13 @@ setMethod("dbWriteTable", "MonetDBConnec
                })
 
 
-setMethod("dbDataType", signature(dbObj="MonetDBConnection", obj = "ANY"), def 
= function(dbObj, obj, ...) {
+setMethod("dbDataType", signature(dbObj="MonetDBConnection", obj = "ANY"), 
def=function(dbObj, obj, ...) {
                        if (is.logical(obj)) "BOOLEAN"
                        else if (is.integer(obj)) "INTEGER"
                        else if (is.numeric(obj)) "DOUBLE PRECISION"
                        else if (is.raw(obj)) "BLOB"
                        
-                       else "VARCHAR(255)"
+                       else "STRING"
                }, valueClass = "character")
 
 
diff --git a/clients/R/MonetDB.R/R/monetframe.R 
b/clients/R/MonetDB.R/R/monetframe.R
deleted file mode 100644
--- a/clients/R/MonetDB.R/R/monetframe.R
+++ /dev/null
@@ -1,1218 +0,0 @@
-# this wraps a sql database (in particular MonetDB) with a DBI connector 
-# to have it appear like a data.frame
-
-# shorthand constructor, also creates connection to db
-mf <- 
function(database,table,host="localhost",port=50000,user="monetdb",pass="monetdb",debug=FALSE,timeout=100)
 {
-       dburl <- paste0("monetdb://",host,":",port,"/",database)        
-       con <- dbConnect(MonetDB.R(), dburl,user,pass,timeout=timeout)
-       monet.frame(con,table,debug)
-}
-
-# can either be given a query or simply a table name
-# now supports hints on table structure to speed up initialization
-monet.frame <-  monetframe <- function(conn,tableOrQuery,debug=FALSE) 
monet.frame.internal(conn,tableOrQuery,debug)
-
-monet.frame.internal <- 
function(conn,tableOrQuery,debug=FALSE,rtypes.hint=NA,cnames.hint=NA,ncol.hint=NA,nrow.hint=NA)
 {
-       if(missing(conn)) stop("'conn' must be specified")
-       if(missing(tableOrQuery)) stop("a sql query or a table name must be 
specified")
-       
-       obj = new.env()
-       class(obj) = "monet.frame"
-       attr(obj,"conn") <- conn
-       query <- tableOrQuery
-       
-       if (length(grep("^SELECT.*",tableOrQuery,ignore.case=TRUE)) == 0) {
-               query <- paste0("SELECT * FROM 
",make.db.names(conn,tableOrQuery,allow.keywords=FALSE))
-       }
-       
-       attr(obj,"query") <- query
-       attr(obj,"debug") <- debug
-       
-       if (debug) cat(paste0("QQ: '",query,"'\n",sep=""))      
-       # do this here, in case the nrow thing needs it
-       coltestquery <- gsub("SELECT (.*?) FROM (.*?) 
(ORDER|LIMIT|OFFSET).*","SELECT \\1 FROM \\2",query,ignore.case=TRUE)
-       
-       if (!is.na(cnames.hint) && !is.na(ncol.hint) && !is.na(rtypes.hint)) {
-               attr(obj,"cnames") <- cnames.hint
-               attr(obj,"ncol") <- ncol.hint
-               attr(obj,"rtypes") <- rtypes.hint
-               
-       } else {
-               # strip away things the prepare does not like
-               coltestquery <- gsub("SELECT (.*?) FROM (.*?) 
(ORDER|LIMIT|OFFSET).*","SELECT \\1 FROM \\2",query,ignore.case=TRUE)
-               
-               # get column names and types from prepare response
-               res <- dbGetQuery(conn, paste0("PREPARE ",coltestquery))
-               attr(obj,"cnames") <- res$column
-               attr(obj,"ncol") <- length(res$column)
-               attr(obj,"rtypes") <- lapply(res$type,monetdbRtype)
-               
-               if (debug) cat(paste0("II: 'Re-Initializing column 
info.'\n",sep=""))   
-               
-       }
-       
-       if (!is.na(nrow.hint)) {
-               attr(obj,"nrow") <- nrow.hint
-       }
-       else {
-               # get result set length by rewriting to count(*), should be 
much faster
-               # temporarily remove offset/limit, as this screws up counting
-               counttestquery <- sub("(SELECT )(.*?)( 
FROM.*)","\\1COUNT(*)\\3",coltestquery,ignore.case=TRUE)
-               nrow <- dbGetQuery(conn,counttestquery)[[1,1]] - 
.getOffset(query)
-       
-               limit <- .getLimit(query)
-               if (limit > 0) nrow <- min(nrow,limit)
-               if (nrow < 1) 
-                       warning(query, " has zero-row result set.")
-               
-               attr(obj,"nrow") <- nrow
-               if (debug) cat(paste0("II: 'Re-Initializing row 
count.'\n",sep=""))     
-               
-       }
-       return(obj)
-}
-
-set.debug <- function(x,debug){
-       attr(x,"debug") <- debug
-}
-
-.is.debug <- function(x) {
-       attr(x,"debug")
-}
-
-.element.limit <- 10000000
-
-as.data.frame.monet.frame <- adf <- function(x, row.names, optional, 
warnSize=TRUE,...) {
-       # check if amount of tuples/fields is larger than some limit
-       # raise error if over limit and warnSize==TRUE
-       if (ncol(x)*nrow(x) > .element.limit && warnSize) 
-               stop(paste0("The total number of elements to be loaded is 
larger than ",.element.limit,". This is probably very slow. Consider dropping 
columns and/or rows, e.g. using the [] function. If you really want to do this, 
call as.data.frame() with the warnSize parameter set to FALSE."))
-       # get result set object from frame
-       if (.is.debug(x)) cat(paste0("EX: '",attr(x,"query"),"'\n",sep=""))     
-       
-       return(dbGetQuery(attr(x,"conn"),attr(x,"query")))
-}
-
-as.vector.monet.frame <- av <- function(x,...) {
-       if (ncol(x) != 1)
-               stop("as.vector can only be used on one-column monet.frame 
objects. Consider using $.")
-       as.data.frame(x)[[1]]
-}
-
-# this is the fun part. this method has infinity ways of being invoked :(
-# 
http://stat.ethz.ch/R-manual/R-patched/library/base/html/Extract.data.frame.html
-
-# TODO: handle negative indices and which() calls. which() like subset!
-# TODO: subset calls destroy nrows hint
-
-"[.monet.frame" <- function(x, k, j,drop=TRUE) {       
-       nquery <- query <- getQuery(x)
-       
-       cols <- NA
-       rows <- NA
-       
-       nrow.hint <- nrow(x)
-       ncol.hint <- ncol(x)
-       cnames.hint <- NA
-       rtypes.hint <- NA
-       
-       # biiig fun with nargs to differentiate d[1,] and d[1]
-       # all in the presence of the optional drop argument, yuck!
-       args <- nargs()
-       if (!missing(drop)) {
-               args <- args-1
-       }
-       if (args == 2 && missing(j)) cols <- k
-       if (args == 3 && !missing(j)) cols <- j
-       if (args == 3 && !missing(k)) rows <- k
-               
-       if (length(cols) > 1 || !is.na(cols)) { # get around an error if cols 
is a vector...
-               # if we have a numeric column spec, find the appropriate names
-               if (is.numeric(cols)) {
-                       if (min(cols) < 1 || max(cols) > ncol(x)) 
-                               stop(paste0("Invalid column specification 
'",cols,"'. Column indices have to be in range [1,",ncol(x),"].",sep=""))       
              
-                       cols <- names(x)[cols]
-               }
-               if (!all(cols %in% names(x)))
-                       stop(paste0("Invalid column specification '",cols,"'. 
Column names have to be in set {",paste(names(x),collapse=", "),"}.",sep=""))   
                  
-               
-               rtypes.hint <- rTypes(x)[match(cols,names(x)),drop=TRUE]
-               ncol.hint <- length(cols)
-               cnames.hint <- cols
-               
-               nquery <- sub("SELECT.+FROM",paste0("SELECT 
",paste0(make.db.names(attr(x,"conn"),cols),collapse=", ")," FROM"),query)
-       }
-       
-       if (length(rows) > 1 || !is.na(rows)) { # get around an error if cols 
is a vector...
-               if (min(rows) < 1 || max(rows) > nrow(x)) 
-                       stop("Invalid row specification. Row indices have to be 
in range [1,",nrow(x),"].",sep="")                      
-               
-               if (.is.sequential(rows)) {
-                       # find out whether we already have limit and/or offset 
set
-                       # our values are relative to them
-       
-                       offset <- .getOffset(nquery) + min(rows)-1 # offset 
means skip n rows, but r lower limit includes them
-                       limit <- max(rows)-min(rows)+1
-
-                       # remove old limit/offset from query
-                       # TODO: is this safe? UNION queries are particularly 
dangerous, again...
-                       nquery <- gsub("limit[ ]+\\d+|offset[ 
]+\\d+","",nquery,ignore.case=TRUE)
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to