Changeset: ff8b818a5a3c for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ff8b818a5a3c Added Files: clients/R/MonetDB.R/man/dbApply.Rd Modified Files: clients/R/MonetDB.R/NEWS clients/R/MonetDB.R/R/control.R clients/R/MonetDB.R/R/dbapply.R clients/R/MonetDB.R/R/dbi.R clients/R/MonetDB.R/R/dplyr.R Branch: default Log Message:
R Connector: Documentation for dbApply() and CRAN checks diffs (123 lines): 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,11 +1,10 @@ -0.9.9 -- dbWriteTable now quotes table/column names if necessary, and outputs warnings if it did -- New dbApply function to automatically create embedded R functions in MonetDB - 0.9.8 - Added support for esoteric data types such as MONTH_INTERVAL (Thanks, Roman) - Cleaned up SQL to R type mapping (we had this twice) - Now creating actual R integers if data fits +- dbWriteTable now quotes table/column names if necessary, and outputs warnings if it did +- New dbApply function to automatically create embedded R functions in MonetDB +- Fixes for dplyr backend 0.9.7 - Fixed crash on Windows (Sorry, everyone) diff --git a/clients/R/MonetDB.R/R/control.R b/clients/R/MonetDB.R/R/control.R --- a/clients/R/MonetDB.R/R/control.R +++ b/clients/R/MonetDB.R/R/control.R @@ -5,7 +5,7 @@ monetdb.server.start <- if( !file.exists( bat.file ) ) stop( paste( bat.file , "does not exist. Run monetdb.server.setup() to create a batch file." ) ) # uugly, find path of pid file again by parsing shell script. - sc <- read.table(bat.file,sep="\n",stringsAsFactors=F) + sc <- utils::read.table(bat.file,sep="\n",stringsAsFactors=F) pidfile <- substring(sc[[2,1]],11) # run script diff --git a/clients/R/MonetDB.R/R/dbapply.R b/clients/R/MonetDB.R/R/dbapply.R --- a/clients/R/MonetDB.R/R/dbapply.R +++ b/clients/R/MonetDB.R/R/dbapply.R @@ -8,11 +8,12 @@ # TODO: optionally inline serialized context for remote dbs res <- tempfile() - save(list=vars,file=res,envir=environment(name),compress=T) + save(list=vars,file=res,envir=environment(name), compress=T) return(res) } -if (is.null(getGeneric("dbApply"))) setGeneric("dbApply", function(conn, ...) +# TOOD: support running this on query results? +if (is.null(getGeneric("dbApply"))) setGeneric("dbApply", function(conn, table, rettype, fun) standardGeneric("dbApply")) setMethod("dbApply", signature(conn="MonetDBConnection"), def=function(conn, table, rettype, fun) { diff --git a/clients/R/MonetDB.R/R/dbi.R b/clients/R/MonetDB.R/R/dbi.R --- a/clients/R/MonetDB.R/R/dbi.R +++ b/clients/R/MonetDB.R/R/dbi.R @@ -22,8 +22,8 @@ setMethod("dbUnloadDriver", "MonetDBDriv setMethod("dbGetInfo", "MonetDBDriver", def=function(dbObj, ...) list(name="MonetDBDriver", - driver.version=packageVersion("MonetDB.R"), - DBI.version=packageVersion("DBI"), + driver.version=utils::packageVersion("MonetDB.R"), + DBI.version=utils::packageVersion("DBI"), client.version="NA", max.connections=125) # R can only handle 128 connections, three of which are pre-allocated ) @@ -624,7 +624,7 @@ monet.read.csv <- monetdb.read.csv <- fu delim=",", newline="\\n", quote="\"", create=TRUE, ...){ if (length(na.strings)>1) stop("na.strings must be of length 1") - headers <- lapply(files, read.csv, sep=delim, na.strings=na.strings, quote=quote, nrows=nrow.check, + headers <- lapply(files, utils::read.csv, sep=delim, na.strings=na.strings, quote=quote, nrows=nrow.check, ...) if (!missing(nrows)) { diff --git a/clients/R/MonetDB.R/R/dplyr.R b/clients/R/MonetDB.R/R/dplyr.R --- a/clients/R/MonetDB.R/R/dplyr.R +++ b/clients/R/MonetDB.R/R/dplyr.R @@ -14,7 +14,8 @@ src_translate_env.src_monetdb <- functio sd = dplyr::sql_prefix("STDDEV_SAMP"), var = dplyr::sql_prefix("VAR_SAMP"), median = dplyr::sql_prefix("MEDIAN"), - n_distinct = function(x) {build_sql(sql("count(distinct "),x,sql(")"))} + n_distinct = function(x) {dplyr::build_sql(dplyr::sql("count(distinct "), + x, dplyr::sql(")"))} ) ) } diff --git a/clients/R/MonetDB.R/man/dbApply.Rd b/clients/R/MonetDB.R/man/dbApply.Rd new file mode 100644 --- /dev/null +++ b/clients/R/MonetDB.R/man/dbApply.Rd @@ -0,0 +1,34 @@ +\name{dbApply} +\alias{dbApply} +\alias{dbApply,MonetDBConnection-method} + +\title{ + Apply a R function to a MonetDB table. +} +\description{ +\code{dbApply} is used to switch the data from the normal auto-commiting mode into transactional mode. Here, changes to the database will not be permanent until \code{dbCommit} is called. If the changes are not to be kept around, you can use \code{dbRollback} to undo all the changes since \code{dbTransaction} was called. + +} +\usage{ + dbApply(conn, table, rettype, fun) +} +\arguments{ + \item{conn}{A MonetDB.R database connection. Created using \code{\link[DBI]{dbConnect}} + with the \code{\link[MonetDB.R]{MonetDB.R}} database driver.} + \item{table}{A MonetDB database table. Can also be a view or temporary table.} + \item{rettype}{SQL type the function returns. Case-insensitive. For example, \code{INTEGER}, \code{DOUBLE}, \code{STRING} etc.} + \item{fun}{A R function to be run on the database table. The function gets passed a single \code{data.frame} argument which represents the database table. The function needs to return a single vector (for now).} + } +\value{ + Returns the result of the function applied to the database table. +} +\examples{ +\dontrun{ +conn <- dbConnect(MonetDB.R(), "demo") +data(mtcars) +dbWriteTable(conn, "mtcars", mtcars) + +mpgplus42 <- dbApply(conn, "mtcars", "double", function(d) { + d$mpg + 42 +}) +}} _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list