Changeset: 2ffee97139b5 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2ffee97139b5
Added Files:
        clients/R/db.tests/monetdb.test.R
        clients/R/db.tests/monetframe.test.R
        clients/R/db.tests/sqlsurvey.test.R
Modified Files:
        clients/R/MonetDB.R/DESCRIPTION
        clients/R/MonetDB.R/NEWS
        clients/R/MonetDB.R/R/monetdb.R
        clients/R/MonetDB.R/man/monetdb.read.csv.Rd
        clients/R/MonetDB.R/src/mapisplit.c
Branch: default
Log Message:

R Connector updates for CRAN


diffs (truncated from 415 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.2
-Date: 2013-10-16
+Version: 0.9
+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: DBI (>= 0.2-5), digest (>= 0.6.0),methods
+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/NEWS b/clients/R/MonetDB.R/NEWS
--- a/clients/R/MonetDB.R/NEWS
+++ b/clients/R/MonetDB.R/NEWS
@@ -1,6 +1,18 @@
+0.8.5
+- added parameters newline and quote to monetdb.write.csv
+
+0.8.4
+- fixed bug when reading empty table (Thanks, Anthony)
+- removed assertion in mapisplit.c that triggered sometimes for unclear reasons
+
+0.8.3
+- fixed a problem where integer SEXPs turned to double somehow
+
+0.8.2
+- fixed bug in dbConnect() where port and timeout were not always integer 
values
+
 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)
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
@@ -27,21 +27,24 @@ MonetR <- MonetDB <- MonetDBR <- MonetDB
 
 setMethod("dbGetInfo", "MonetDBDriver", def=function(dbObj, ...)
                        list(name="MonetDBDriver", 
-                                       driver.version="0.8.0",
+                                       driver.version="0.9",
                                        DBI.version="0.2-5",
                                        client.version=NA,
                                        max.connections=NA)
 )
 
 # shorthand for connecting to the DB, very handy, e.g. dbListTables(mc("acs"))
-mc <- function(dbname="demo", user="monetdb", password="monetdb", 
host="localhost",port=50000, timeout=86400, wait=FALSE,...) {
+mc <- function(dbname="demo", user="monetdb", password="monetdb", 
host="localhost",port=50000L, timeout=86400L, wait=FALSE,...) {
        dbConnect(MonetDB.R(),dbname,user,password,host,port,timeout,wait,...)
 }
 
-setMethod("dbConnect", "MonetDBDriver", def=function(drv,dbname="demo", 
user="monetdb", password="monetdb", host="localhost",port=50000, timeout=86400, 
wait=FALSE,...,url="") {
+setMethod("dbConnect", "MonetDBDriver", def=function(drv,dbname="demo", 
user="monetdb", password="monetdb", host="localhost",port=50000L, 
timeout=86400L, wait=FALSE,...,url="") {
                        if (substring(url,1,10) == "monetdb://") {
                                dbname <- url
                        }
+                       port <- as.integer(port)
+                       timeout <- as.integer(timeout)
+                       
                        if (substring(dbname,1,10) == "monetdb://") {
                                #warning("MonetDB.R: Using 'monetdb://...' URIs 
in dbConnect() is deprecated. Please switch to dbname, host, port named 
arguments.")
                                rest <- substring(dbname,11,nchar(dbname))
@@ -239,7 +242,7 @@ 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"
@@ -412,7 +415,7 @@ setMethod("fetch", signature(res="MonetD
                        #parts[parts=="NULL"] <- NA
                        
                        # call to a faster C implementation for the hard and 
annoying task of splitting everyting into fields
-                       parts <- .Call("mapiSplit", 
res@env$data[1:n],info$cols, PACKAGE=C_LIBRARY)
+                       parts <- .Call("mapiSplit", 
res@env$data[1:n],as.integer(info$cols), PACKAGE=C_LIBRARY)
                        
                        # convert values column by column
                        for (j in seq.int(info$cols)) { 
@@ -642,8 +645,8 @@ REPLY_SIZE    <- 100 # Apparently, -1 me
                        env$types       <- env$dbtypes <- 
toupper(.mapiParseTableHeader(lines[4]))
                        env$lengths     <- .mapiParseTableHeader(lines[5])
                        
-                       env$tuples <-lines[6:length(lines)]
-
+                       if (env$rows > 0) env$tuples <- lines[6:length(lines)]
+                       
                        stopifnot(length(env$tuples) == header$index)
                        return(env)
                }
@@ -779,13 +782,21 @@ REPLY_SIZE    <- 100 # Apparently, -1 me
        
 }
 
+.hasColFunc <- function(conn,func) {
+       tryCatch({
+                               r <- dbSendQuery(conn,paste0("SELECT 
",func,"(1);"))
+                               TRUE
+                       }, error = function(e) {
+                               FALSE
+                       })
+}
 
 # copied from RMonetDB, no java-specific things in here...
 # TODO: read first few rows with read.table and check types etc.
 
-monet.read.csv <- monetdb.read.csv <- 
function(conn,files,tablename,nrows,header=TRUE,locked=FALSE,na.strings="",...,nrow.check=500,delim=","){
+monet.read.csv <- monetdb.read.csv <- 
function(conn,files,tablename,nrows,header=TRUE,locked=FALSE,na.strings="",nrow.check=500,delim=",",newline="\\n",quote="\"",...){
        if (length(na.strings)>1) stop("na.strings must be of length 1")
-       headers<-lapply(files,read.csv,na.strings="NA",...,nrows=nrow.check)
+       
headers<-lapply(files,read.csv,na.strings="NA",quote=quote,nrows=nrow.check,...)
        
        if (length(files)>1){
                nn<-sapply(headers,ncol)
@@ -797,17 +808,19 @@ monet.read.csv <- monetdb.read.csv <- fu
        } 
        
        dbWriteTable(conn, tablename, headers[[1]][FALSE,])
+
+       delimspec <- paste0("USING DELIMITERS 
'",delim,"','",newline,"','",quote,"'")
        
        if(header || !missing(nrows)){
                if (length(nrows)==1) nrows<-rep(nrows,length(files))
                for(i in seq_along(files)) {
                        cat(files[i],thefile<-normalizePath(files[i]),"\n")
-                       dbSendUpdate(conn, 
paste("copy",format(nrows[i],scientific=FALSE),"offset 2 records into", 
tablename,"from",paste("'",thefile,"'",sep=""),"using delimiters ',','\\n','\"' 
NULL as",paste("'",na.strings[1],"'",sep=""),if(locked) "LOCKED"))
+                       dbSendUpdate(conn, 
paste("COPY",format(nrows[i],scientific=FALSE),"OFFSET 2 RECORDS INTO", 
tablename,"FROM",paste("'",thefile,"'",sep=""),delimspec,"NULL 
as",paste("'",na.strings[1],"'",sep=""),if(locked) "LOCKED"))
                }
        } else {
                for(i in seq_along(files)) {
                        cat(files[i],thefile<-normalizePath(files[i]),"\n")
-                       dbSendUpdate(conn, paste0("copy into ", tablename," 
from ",paste("'",thefile,"'",sep="")," using delimiters '",delim,"','\\n','\"' 
NULL as ",paste("'",na.strings[1],"'",sep=""),if(locked) " LOCKED "))
+                       dbSendUpdate(conn, paste0("COPY INTO ", tablename," 
FROM ",paste("'",thefile,"'",sep=""),delimspec,"NULL as 
",paste("'",na.strings[1],"'",sep=""),if(locked) " LOCKED "))
                }
        }
        dbGetQuery(conn,paste("select count(*) from",tablename))
diff --git a/clients/R/MonetDB.R/man/monetdb.read.csv.Rd 
b/clients/R/MonetDB.R/man/monetdb.read.csv.Rd
--- a/clients/R/MonetDB.R/man/monetdb.read.csv.Rd
+++ b/clients/R/MonetDB.R/man/monetdb.read.csv.Rd
@@ -10,7 +10,8 @@
 }
 \usage{
    monetdb.read.csv (conn, files, tablename, nrows, header=TRUE, 
-  locked=FALSE, na.strings="", ..., nrow.check=500, delim=",")
+  locked=FALSE, na.strings="", nrow.check=500, delim=",",
+  newline = "\\\\n", quote = "\"", ...)
 }
 \arguments{
   \item{conn}{A MonetDB.R database connection. Created using 
\code{\link[DBI]{dbConnect}} with the 
@@ -26,6 +27,8 @@
    \item{nrow.check}{Amount of rows that should be read from the CSV when the 
    table is being created to determine column types.}
    \item{delim}{Field separator in CSV file.}
+   \item{newline}{Newline in CSV file, usually \\n for UNIX-like systems and 
\\r\\r on Windows.}
+   \item{quote}{Quote character(s) in CSV file.}
  }
  
 \value{
diff --git a/clients/R/MonetDB.R/src/mapisplit.c 
b/clients/R/MonetDB.R/src/mapisplit.c
--- a/clients/R/MonetDB.R/src/mapisplit.c
+++ b/clients/R/MonetDB.R/src/mapisplit.c
@@ -131,7 +131,6 @@ SEXP mapiSplit(SEXP mapiLinesVector, SEX
                                break;
                        }
                }
-               assert(cCol == cols - 1);
        }
        free(valPtr);
 
diff --git a/clients/R/db.tests/monetdb.test.R 
b/clients/R/db.tests/monetdb.test.R
new file mode 100644
--- /dev/null
+++ b/clients/R/db.tests/monetdb.test.R
@@ -0,0 +1,93 @@
+library(MonetDB.R)
+
+drv <- dbDriver("MonetDB")
+stopifnot(identical(dbGetInfo(drv)$name,"MonetDBDriver"))
+
+con <- dbConnect(drv, "monetdb://localhost:50000/monetdbrtest", "monetdb", 
"monetdb",timeout=100,debug.queries=T)
+stopifnot(identical(class(con)[[1]],"MonetDBConnection"))
+# overwrite variable to force destructor
+con <- dbConnect(drv, "monetdb://localhost:50000/monetdbrtest", "monetdb", 
"monetdb",timeout=100,debug.queries=T)
+con <- dbConnect(drv, "monetdb://localhost:50000/monetdbrtest", "monetdb", 
"monetdb",timeout=100,debug.queries=T)
+gc()
+
+# basic MAPI/SQL test
+stopifnot(identical(dbGetQuery(con,"SELECT 'DPFKG!'")[[1]],"DPFKG!"))
+
+# remove test table
+if (dbExistsTable(con,"monetdbtest")) dbRemoveTable(con,"monetdbtest")
+stopifnot(identical(dbExistsTable(con,"monetdbtest"),FALSE))
+
+
+# test raw handling
+dbSendUpdate(con,"CREATE TABLE monetdbtest (a varchar(10),b integer,c blob)")
+stopifnot(identical(dbExistsTable(con,"monetdbtest"),TRUE))
+dbSendUpdate(con,"INSERT INTO monetdbtest VALUES ('one',1,'1111')")
+dbSendUpdate(con,"INSERT INTO monetdbtest VALUES ('two',2,'22222222')")
+stopifnot(identical(dbGetQuery(con,"SELECT count(*) FROM monetdbtest")[[1]],2))
+stopifnot(identical(dbReadTable(con,"monetdbtest")[[3]],list(charToRaw("1111"),charToRaw("22222222"))))
+
+dbRemoveTable(con,"monetdbtest")
+stopifnot(identical(dbExistsTable(con,"monetdbtest"),FALSE))
+
+
+# write test table iris
+data(iris)
+dbWriteTable(con,"monetdbtest",iris)
+
+stopifnot(identical(dbExistsTable(con,"monetdbtest"),TRUE))
+stopifnot(identical(dbExistsTable(con,"monetdbtest2"),FALSE))
+stopifnot("monetdbtest" %in% dbListTables(con))
+
+stopifnot(identical(dbListFields(con,"monetdbtest"),c("sepal_length","sepal_width","petal_length","petal_width","species")))
+# get stuff, first very convenient
+iris2 <- dbReadTable(con,"monetdbtest")
+stopifnot(identical(dim(iris),dim(iris2)))
+
+
+# then manually
+res <- dbSendQuery(con,"SELECT species, sepal_width FROM monetdbtest")
+stopifnot(identical(class(res)[[1]],"MonetDBResult"))
+stopifnot(identical(res@env$success,TRUE))
+
+stopifnot(dbColumnInfo(res)[[1,1]] == "species")
+stopifnot(dbColumnInfo(res)[[2,1]] == "sepal_width")
+
+stopifnot(dbGetInfo(res)$row.count == 150 && res@env$info$rows == 150)
+
+data <- fetch(res,10)
+stopifnot(dim(data)[[1]] == 10)
+stopifnot(dim(data)[[2]] == 2)
+stopifnot(res@env$delivered == 10)
+stopifnot(dbHasCompleted(res) == FALSE)
+
+data2 <- fetch(res,-1)
+stopifnot(dim(data2)[[1]] == 140)
+stopifnot(dbHasCompleted(res) == TRUE)
+
+dbClearResult(res)
+
+# remove table again
+dbRemoveTable(con,"monetdbtest")
+stopifnot(identical(dbExistsTable(con,"monetdbtest"),FALSE))
+
+# test csv import
+file <- tempfile()
+write.table(iris,file,sep=",")
+monetdb.read.csv(con,file,"monetdbtest",150)
+unlink(file)
+stopifnot(identical(dbExistsTable(con,"monetdbtest"),TRUE))
+iris3 <- dbReadTable(con,"monetdbtest")
+stopifnot(identical(dim(iris),dim(iris3)))
+stopifnot(identical(dbListFields(con,"monetdbtest"),c("sepal_length","sepal_width","petal_length","petal_width","species")))
+dbRemoveTable(con,"monetdbtest")
+stopifnot(identical(dbExistsTable(con,"monetdbtest"),FALSE))
+
+
+
+stopifnot(identical(dbDisconnect(con),TRUE))
+stopifnot(identical(dbDisconnect(con),TRUE))
+stopifnot(identical(dbDisconnect(con),TRUE))
+
+#thrice to catch pointer errors
+
+print("SUCCESS")
diff --git a/clients/R/db.tests/monetframe.test.R 
b/clients/R/db.tests/monetframe.test.R
new file mode 100644
--- /dev/null
+++ b/clients/R/db.tests/monetframe.test.R
@@ -0,0 +1,75 @@
+library(monet.frame)
+
+con <- dbConnect(dbDriver("MonetDB"), 
"monetdb://localhost:50000/monetdbrtest", "monetdb", "monetdb",timeout=100)
+
+table <- "monetframetest"
+
+
+fcmp <- function(f1,f2,epsilon) {
+       abs(f1-f2) < epsilon
+}
+
+# basic MAPI/SQL test
+stopifnot(identical(dbGetQuery(con,"SELECT 'DPFKG!'")[[1]],"DPFKG!"))
+
+if (!dbExistsTable(con,table)) {
+       data(iris)
+       dbWriteTable(con,table,iris, overwrite=TRUE)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to