Changeset: 5cbd97f0cd7d for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5cbd97f0cd7d Added Files: clients/R/MonetDB.R/man/sqlitecompat.Rd Modified Files: clients/R/MonetDB.R/DESCRIPTION clients/R/MonetDB.R/NEWS clients/R/MonetDB.R/R/dbi.R clients/R/MonetDB.R/R/dplyr.R clients/R/MonetDB.R/man/MonetDB.R.Rd clients/R/MonetDB.R/man/MonetDBLite.Rd clients/R/MonetDB.R/man/control.Rd clients/R/MonetDB.R/man/monetdb.read.csv.Rd clients/R/MonetDB.R/man/src_monetdb.Rd clients/R/Tests/dbapply.R clients/R/Tests/dplyr-flights.R clients/R/Tests/dplyr.R clients/R/build-for-cran.sh Branch: embedded Log Message:
r client test case and doc fixes diffs (truncated from 382 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 @@ -11,6 +11,6 @@ Enhances: dplyr (>= 0.3.0), MonetDBLite Description: Allows to pull data from MonetDB into R. Includes a DBI implementation and a dplyr backend. License: MPL (== 2.0) URL: http://monetr.r-forge.r-project.org -SystemRequirements: MonetDB, available from http://www.monetdb.org +SystemRequirements: MonetDB, available from http://www.monetdb.org or MonetDBLite R package Collate: mapi.R dbi.R dbapply.R dplyr.R control.R Additional_repositories: http://dev.monetdb.org/Assets/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,7 +1,7 @@ 1.0.1 - added isIdCurrent for improved compatibility with RSQLite - new option monetdb.log.query allows export of dbSendQuery statements to file -- no longer depends on DBI but imports it +- no longer depends on DBI but imports it. Preferred way of constructing connections: library(DBI); con <- dbConnect(MonetDB.R::MonetDB(), ...) 1.0.0 - Added support for esoteric data types such as MONTH_INTERVAL (Thanks, Roman) 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 @@ -440,6 +440,7 @@ reserved_monetdb_keywords <- sort(unique # quoting quoteIfNeeded <- function(conn, x, warn=T, ...) { + x <- as.character(x) chars <- !grepl("^[a-z_][a-z0-9_]*$", x, perl=T) & !grepl("^\"[^\"]*\"$", x, perl=T) if (any(chars) && warn) { message("Identifier(s) ", paste("\"", x[chars],"\"", collapse=", ", sep=""), " contain uppercase or reserved SQL characters and need(s) to be quoted in queries.") 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 @@ -4,6 +4,10 @@ src_monetdb <- function(dbname="demo", h con <- DBI::dbConnect(MonetDB.R(), dbname = dbname , host = host, port = port, user = user, password = password, ...) } + pkgname <- "MonetDB.R" + if (!(pkgname %in% loadedNamespaces())) { + attachNamespace(pkgname) + } dplyr::src_sql("monetdb", con, info = DBI::dbGetInfo(con)) } @@ -65,7 +69,7 @@ db_query_rows.MonetDBConnection <- funct } db_query_rows.MonetDBEmbeddedConnection <- function(con, sql, ...) { - attr(dbGetQuery(con, sql, notreally=T), "__rows") + attr(DBI::dbGetQuery(con, sql, notreally=T), "__rows") } db_insert_into.MonetDBConnection <- function(con, table, values, ...) { diff --git a/clients/R/MonetDB.R/man/MonetDB.R.Rd b/clients/R/MonetDB.R/man/MonetDB.R.Rd --- a/clients/R/MonetDB.R/man/MonetDB.R.Rd +++ b/clients/R/MonetDB.R/man/MonetDB.R.Rd @@ -34,12 +34,11 @@ } \examples{ \dontrun{ -conn <- dbConnect(MonetDB.R(), "monetdb://localhost/demo") +library(DBI) +conn <- dbConnect(MonetDB.R::MonetDB(), dbname = "demo") +dbWriteTable(conn, "iris", iris) dbListTables(conn) -data(iris) -dbWriteTable(conn, "iris", iris) -dbGetQuery(conn, "SELECT COUNT(*) FROM iris;") +dbGetQuery(conn, "SELECT COUNT(*) FROM iris") d <- dbReadTable(conn, "iris") - }} \keyword{interface} diff --git a/clients/R/MonetDB.R/man/MonetDBLite.Rd b/clients/R/MonetDB.R/man/MonetDBLite.Rd --- a/clients/R/MonetDB.R/man/MonetDBLite.Rd +++ b/clients/R/MonetDB.R/man/MonetDBLite.Rd @@ -18,12 +18,12 @@ \code{\link[DBI]{dbConnect}}. } \details{ - The \code{MonetDB.R} function creates the R object which can be used to a + The \code{MonetDBLite} function creates the R object which can be used to a call \code{\link[DBI]{dbConnect}} which actually creates the connection. Since it has no parameters, it is most commonly used inline with the \code{\link[DBI]{dbConnect}} call. } \examples{ \dontrun{ -conn <- dbConnect(MonetDBLite(), tempdir()) - +library(DBI) +conn <- dbConnect(MonetDB.R::MonetDBLite()) }} diff --git a/clients/R/MonetDB.R/man/control.Rd b/clients/R/MonetDB.R/man/control.Rd --- a/clients/R/MonetDB.R/man/control.Rd +++ b/clients/R/MonetDB.R/man/control.Rd @@ -3,6 +3,8 @@ \alias{monetdb.server.setup} \alias{monetdb.server.start} \alias{monetdb.server.stop} +\alias{monetdb.server.shutdown} +\alias{monetdb.server.getpid} \title{ Control a MonetDB server from the R shell. @@ -12,13 +14,17 @@ The MonetDB server can be controlled fro The general process is to generate a MonetDb database directory and startup script using \code{monetdb.server.setup}, then pass the path to the startup script to \code{monetdb.server.start}. This function will return the process id of the database server, which in turn can be passed to -\code{monetdb.server.stop} to stop the database server again. +\code{monetdb.server.stop} to stop the database server again. The process ID of a running MonetDB server can also be querid using \code{monetdb.server.getpid}, which takes a DBI connection as a parameter. A better alternative to \code{monetdb.server.stop} is \code{monetdb.server.shutdown}, which takes a DBI connection to shut down the server. + +All of these external server process control functions are deprecated in favor of MonetDBLite. } \usage{ monetdb.server.setup(database.directory,monetdb.program.path, dbname = "demo", dbport = 50000) monetdb.server.start(bat.file) +monetdb.server.getpid(con) monetdb.server.stop(correct.pid, wait = TRUE) +monetdb.server.shutdown(con) } \arguments{ \item{database.directory}{Path to the directory where the initialization script and all data will be stored. Must be empty or non-existant.} @@ -28,6 +34,7 @@ monetdb.server.stop(correct.pid, wait = \item{bat.file}{Path to the MonetDB startup script. This path is returned by \code{monetdb.server.setup}} \item{correct.pid}{Process ID of the running MonetDB server. This number is returned by \code{monetdb.server.start}} \item{wait}{Wait for the server to shut down or return immediately} + \item{con}{A DBI connection to MonetDB} } \value{ \code{monetdb.server.setup} returns the path to a MonetDB startup script, which can used many times 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 @@ -11,28 +11,30 @@ \usage{ monetdb.read.csv (conn, files, tablename, header=TRUE, locked=FALSE, best.effort=FALSE, na.strings="", nrow.check=500, delim=",", - newline = "\\\\n", quote = "\"", create=TRUE, col.names=NULL, lower.case.names=FALSE, ...) + newline = "\\\\n", quote = "\"", create=TRUE, col.names=NULL, lower.case.names=FALSE, + sep=delim, ...) } \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{files}{A single string or a vector of strings containing the absolute file names of the CSV files to be imported.} - \item{tablename}{Name of the database table the CSV files should be imported in. Created if necessary.} - \item{header}{Whether or not the CSV files contain a header line.} - \item{locked}{Whether or not to disable transactions for import. - Setting this to TRUE can greatly improve the import performance.} - \item{best.effort}{Use best effort flag when reading csv files and continue importing even if parsing of fields/lines fails.} - \item{na.strings}{Which string value to interpret as \code{NA} value.} - \item{...}{Additional parameters. Currently not in use.} - \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.} + \item{files}{A single string or a vector of strings containing the absolute file names of the CSV files to be imported.} + \item{tablename}{Name of the database table the CSV files should be imported in. Created if necessary.} + \item{header}{Whether or not the CSV files contain a header line.} + \item{locked}{Whether or not to disable transactions for import. + Setting this to TRUE can greatly improve the import performance.} + \item{best.effort}{Use best effort flag when reading csv files and continue importing even if parsing of fields/lines fails.} + \item{na.strings}{Which string value to interpret as \code{NA} value.} + \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.} \item{create}{Create table before importing?} \item{lower.case.names}{Convert all column names to lowercase in the database?} \item{col.names}{Optional column names in case the ones from CSV file should not be used} - } + \item{sep}{alias for \code{delim}} + \item{...}{Additional parameters. Currently not in use.} +} \value{ Returns the number of rows imported if successful. @@ -42,13 +44,13 @@ } \examples{ \dontrun{ +library(DBI) # connect to MonetDB -conn <- dbConnect(MonetDB.R(), "monetdb://localhost/demo") +conn <- dbConnect(MonetDB.R::MonetDB(), dbname = "demo") # write test data to temporary CSV file -data(iris) file <- tempfile() write.table(iris, file, sep=",") # create table and import CSV -monetdb.read.csv(conn, file, "iris") +MonetDB.R::monetdb.read.csv(conn, file, "iris") }} \keyword{interface} diff --git a/clients/R/MonetDB.R/man/sqlitecompat.Rd b/clients/R/MonetDB.R/man/sqlitecompat.Rd new file mode 100644 --- /dev/null +++ b/clients/R/MonetDB.R/man/sqlitecompat.Rd @@ -0,0 +1,23 @@ +\name{sqlite-compatibility} +\alias{sqlite-compatibility} +\alias{initExtension} +\alias{initExtension,MonetDBConnection-method} +\alias{isIdCurrent} +\alias{isIdCurrent,MonetDBConnection-method} +\alias{isIdCurrent,MonetDBResult-method} + +\title{ + Compatibility functions for RSQlite +} +\description{ +Some functions that RSQlite has and that we support to allow MonetDBLite being used as a drop-in replacement. +} +\usage{ +isIdCurrent(dbObj, ...) +initExtension(dbObj, ...) +} +\arguments{ + \item{dbObj}{A MonetDB.R database connection. Created using \code{\link[DBI]{dbConnect}} with the + \code{\link[MonetDB.R]{MonetDB.R}} database driver.} + \item{...}{Additional parameters. Currently not in use.} +} diff --git a/clients/R/MonetDB.R/man/src_monetdb.Rd b/clients/R/MonetDB.R/man/src_monetdb.Rd --- a/clients/R/MonetDB.R/man/src_monetdb.Rd +++ b/clients/R/MonetDB.R/man/src_monetdb.Rd @@ -47,9 +47,10 @@ If you are running a local database, you \examples{ \dontrun{ +library(dplyr) # Connection basics --------------------------------------------------------- # To connect to a database first create a src: -my_db <- src_monetdb(dbname="demo") +my_db <- MonetDB.R::src_monetdb(dbname="demo") # Then reference a tbl within that src my_tbl <- tbl(my_db, "my_table") } diff --git a/clients/R/Tests/dbapply.R b/clients/R/Tests/dbapply.R --- a/clients/R/Tests/dbapply.R +++ b/clients/R/Tests/dbapply.R @@ -13,7 +13,6 @@ if (length(args) > 1) dbname <- args[[2]] options(monetdb.insert.splitsize=10) -options(monetdb.profile=F) tname <- "monetdbtest" @@ -32,19 +31,19 @@ data(mtcars) dbWriteTable(con,tname,mtcars, overwrite=T) stopifnot(identical(TRUE, dbExistsTable(con,tname))) -res <- mdbapply(con, tname, function(d) { +res <- MonetDB.R::mdbapply(con, tname, function(d) { d$mpg }) stopifnot(identical(res, mtcars$mpg)) -res <- mdbapply(con, tname, function(d) { +res <- MonetDB.R::mdbapply(con, tname, function(d) { min(d$mpg) }) stopifnot(identical(res, min(mtcars$mpg))) # model fitting / in-db application fitted <- lm(mpg~., data=mtcars) -predictions <- mdbapply(con, tname, function(d) { +predictions <- MonetDB.R::mdbapply(con, tname, function(d) { predict(fitted, newdata=data.frame(d, stringsAsFactors=T)) }) @@ -66,7 +65,7 @@ stopifnot(haderror) print(haderror) # run simple test again to make sure the error did dbRollback() and we are consistent -res <- mdbapply(con, tname, function(d) { +res <- MonetDB.R::mdbapply(con, tname, function(d) { d$mpg }) stopifnot(identical(res, mtcars$mpg)) @@ -74,7 +73,7 @@ stopifnot(identical(res, mtcars$mpg)) print(length(res)) # additional parameters -res <- mdbapply(con,tname,function(d, n, m) { +res <- MonetDB.R::mdbapply(con,tname,function(d, n, m) { n+m }, 20, 22) diff --git a/clients/R/Tests/dplyr-flights.R b/clients/R/Tests/dplyr-flights.R --- a/clients/R/Tests/dplyr-flights.R +++ b/clients/R/Tests/dplyr-flights.R @@ -8,11 +8,7 @@ ff <- textConnection("asdf", open="w") _______________________________________________ checkin-list mailing list [email protected] https://www.monetdb.org/mailman/listinfo/checkin-list
