Changeset: 26b3524fa0be for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=26b3524fa0be
Removed 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/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
Branch: Oct2014
Log Message:

monet.frame is no longer the way to go, dplyr ftw


Unterschiede (gekürzt von 1857 auf 300 Zeilen):

diff --git a/clients/R/monet.frame/DESCRIPTION 
b/clients/R/monet.frame/DESCRIPTION
deleted file mode 100644
--- a/clients/R/monet.frame/DESCRIPTION
+++ /dev/null
@@ -1,13 +0,0 @@
-Package: monet.frame
-Version: 0.1
-Date: 2013-01-21
-Title: Connect MonetDB to R
-Authors@R: c(person("Hannes Muehleisen", role = c("aut", "cre"),email = 
"[email protected]"),
-       person("Thomas Lumley", role = "ctb"),
-       person("Anthony Damico", role = "ctb"))
-Depends: MonetDB.R (>= 0.8.2), methods, utils, stats
-Description: Virtual Data Object for MonetDB
-License: MPL (== 1.1)
-URL: http://monetr.r-forge.r-project.org
-Maintainer: Hannes Muehleisen <[email protected]>
-SystemRequirements: MonetDB installation, available at http://www.monetdb.org
diff --git a/clients/R/monet.frame/NAMESPACE b/clients/R/monet.frame/NAMESPACE
deleted file mode 100644
--- a/clients/R/monet.frame/NAMESPACE
+++ /dev/null
@@ -1,65 +0,0 @@
-import(MonetDB.R,utils,stats,methods)
-
-# monet.frame things, this is an S3 class
-# constructors
-export(monet.frame)
-export(mf)
-export(set.debug)
-
-# 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)
-
diff --git a/clients/R/monet.frame/NEWS b/clients/R/monet.frame/NEWS
deleted file mode 100644
--- a/clients/R/monet.frame/NEWS
+++ /dev/null
@@ -1,2 +0,0 @@
-0.1
-- moved monet.frame into its own package
diff --git a/clients/R/monet.frame/R/monetframe.R 
b/clients/R/monet.frame/R/monetframe.R
deleted file mode 100644
--- a/clients/R/monet.frame/R/monetframe.R
+++ /dev/null
@@ -1,1295 +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)
-                       nquery <- sub(";? *$",paste0(" LIMIT 
",.mapiLongInt(limit)," OFFSET ",.mapiLongInt(offset)),nquery,ignore.case=TRUE)
-                       nrow.hint <- limit
-               }
-               else 
-                       warning(paste("row specification has to be sequential, 
but ",paste(rows,collapse=",")," is not. Try 
as.data.frame(x)[c(",paste(rows,collapse=","),"),] instead.",sep=""))
-       }
-       
-       # this would be the only case for column selection where the 'drop' 
parameter has an effect.
-       # we have to create a warning, since drop=TRUE is default behaviour and 
might be expected by users
-       if (((!is.na(cols) && length(cols) == 1) || (!is.na(rows) && 
length(rows) == 1)) && drop) 
-               warning("drop=TRUE for one-column or one-row results is not 
supported. Overriding to FALSE")
-       
-       # construct and return new monet.frame for rewritten query
-       
monet.frame.internal(attr(x,"conn"),nquery,.is.debug(x),nrow.hint=nrow.hint,ncol.hint=ncol.hint,
 cnames.hint=cnames.hint, rtypes.hint=rtypes.hint)
-}
-
-.getOffset <- function(query) {
-       os <- 0
-       osStr <- gsub("(.*offset[ ]+)(\\d+)(.*)","\\2",query,ignore.case=TRUE)
-       if (osStr != query) {
-               os <- as.numeric(osStr)
-       }
-       os
-}
-
-.getLimit <- function(query) {
-       l <- 0
-       lStr <- gsub("(.*limit[ ]+)(\\d+)(.*)","\\2",query,ignore.case=TRUE)
-       if (lStr != query) {
-               l <- as.numeric(lStr)
-       }
-       l
-}
-
-.hasColFunc <- function(conn,func) {
-       tryCatch({
-                               r <- dbSendQuery(conn,paste0("SELECT 
",func,"(1);"))
-                               TRUE
-                       }, error = function(e) {
-                               FALSE
-                       })
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to