R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("DBI-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('DBI') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "DBIConnection-class" > > ### * DBIConnection-class > > flush(stderr()); flush(stdout()) > > ### Name: DBIConnection-class > ### Title: Class DBIConnection > ### Aliases: DBIConnection-class > ### Keywords: classes database interface > > ### ** Examples > ## Not run: > ##D ora <- dbDriver("Oracle") > ##D con <- dbConnect(ora, "user/password@dbname") > ##D > ##D pg <- dbDriver("PostgreSQL") > ##D con <- dbConnect(pg, "user", "password") > ## End(Not run) > > > > cleanEx(); ..nameEx <- "DBIDriver-class" > > ### * DBIDriver-class > > flush(stderr()); flush(stdout()) > > ### Name: DBIDriver-class > ### Title: Class DBIDriver > ### Aliases: DBIDriver-class > ### Keywords: classes database interface > > ### ** Examples > ## Not run: > ##D drv <- dbDriver("ODBC") > ##D summary(drv) > ##D dbListConnections(drv) > ## End(Not run) > > > > cleanEx(); ..nameEx <- "DBIObject-class" > > ### * DBIObject-class > > flush(stderr()); flush(stdout()) > > ### Name: DBIObject-class > ### Title: Class DBIObject > ### Aliases: DBIObject-class > ### Keywords: classes interface database > > ### ** Examples > ## Not run: > ##D drv <- dbDriver("MySQL") > ##D con <- dbConnect(drv, group = "rs-dbi") > ##D res <- dbSendQuery(con, "select * from vitalSuite") > ##D is(drv, "DBIObject") ## True > ##D is(con, "DBIObject") ## True > ##D is(res, "DBIObject") > ## End(Not run) > > > > cleanEx(); ..nameEx <- "DBIResult-class" > > ### * DBIResult-class > > flush(stderr()); flush(stdout()) > > ### Name: DBIResult-class > ### Title: Class DBIResult > ### Aliases: DBIResult-class > ### Keywords: classes interface database > > ### ** Examples > ## Not run: > ##D drv <- dbDriver("Oracle") > ##D con <- dbConnect(drv, "user/password@dbname") > ##D res <- dbSendQuery(con, "select * from LASERS where prdata > '2002-05-01'") > ##D summary(res) > ##D while(dbHasCompleted(res)){ > ##D chunk <- fetch(res, n = 1000) > ##D process(chunk) > ##D } > ## End(Not run) > > > > cleanEx(); ..nameEx <- "dbCommit-methods" > > ### * dbCommit-methods > > flush(stderr()); flush(stdout()) > > ### Name: dbCommit-methods > ### Title: DBMS Transaction Management > ### Aliases: dbCommit dbRollback dbCommit-methods dbRollback-methods > ### dbCommit,DBIConnection-method dbRollback,DBIConnection-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D ora <- dbDriver("Oracle") > ##D con <- dbConnect(ora) > ##D rs <- dbSendQuery(con, > ##D "delete * from PURGE as p where p.wavelength<0.03") > ##D if(dbGetInfo(rs, what = "rowsAffected") > 250){ > ##D warning("dubious deletion -- rolling back transaction") > ##D dbRollback(con) > ##D } > ## End(Not run) > > > > cleanEx(); ..nameEx <- "dbConnect-methods" > > ### * dbConnect-methods > > flush(stderr()); flush(stdout()) > > ### Name: dbConnect-methods > ### Title: Create a connection to a DBMS > ### Aliases: dbDisconnect dbConnect dbDisconnect-methods dbConnect-methods > ### dbDisconnect,DBIConnection-method dbConnect,DBIDriver-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D # create an Oracle instance and create one connection. > ##D drv <- dbDriver("Oracle") > ##D > ##D # open the connection using user, passsword, etc., as > ##D con <- dbConnect(drv, "user/password@dbname") > ##D > ##D # Run an SQL statement by creating first a resultSet object > ##D rs <- dbSendQuery(con, statement = paste( > ##D "SELECT w.laser_id, w.wavelength, p.cut_off", > ##D "FROM WL w, PURGE P", > ##D "WHERE w.laser_id = p.laser_id", > ##D "SORT BY w.laser_id") > ##D # we now fetch records from the resultSet into a data.frame > ##D data <- fetch(rs, n = -1) # extract all rows > ##D dim(data) > ## End(Not run) > > > > cleanEx(); ..nameEx <- "dbDataType-methods" > > ### * dbDataType-methods > > flush(stderr()); flush(stdout()) > > ### Name: dbDataType-methods > ### Title: Determine the SQL Data Type of an S object > ### Aliases: dbDataType dbDataType-methods dbDataType,DBIObject-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D data(quakes) > ##D ora <- dbDriver("MySQL") > ##D sql.type <- dbDataType(ora, quakes) > ## End(Not run) > > > > cleanEx(); ..nameEx <- "dbDriver-methods" > > ### * dbDriver-methods > > flush(stderr()); flush(stdout()) > > ### Name: dbDriver-methods > ### Title: Database Interface (DBI) Classes and drivers > ### Aliases: dbDriver dbUnloadDriver dbDriver-methods > ### dbUnloadDriver-methods dbDriver,character-method > ### dbUnloadDriver,DBIDriver-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D # create a MySQL instance for capacity of up to 25 simultaneous > ##D # connections. > ##D m <- dbDriver("MySQL", max.con = 25) > ##D p <- dbDriver("PgSQL") > ##D > ##D # open the connection using user, password, etc., as > ##D con <- dbConnect(m, user="ip", password = "traffic", dbname="iptraffic") > ##D rs <- dbSubmitQuery(con, > ##D "select * from HTTP_ACCESS where IP_ADDRESS = '127.0.0.1'") > ##D df <- fetch(rs, n = 50) > ##D df2 <- fetch(rs, n = -1) > ##D dbClearResult(rs) > ##D > ##D pcon <- dbConnect(p, "user", "password", "dbname") > ##D dbListTables(pcon) > ## End(Not run) > > > > cleanEx(); ..nameEx <- "dbGetInfo-methods" > > ### * dbGetInfo-methods > > flush(stderr()); flush(stdout()) > > ### Name: dbGetInfo-methods > ### Title: Database interface meta-data > ### Aliases: dbGetInfo dbGetDBIVersion dbGetStatement dbGetRowCount > ### dbGetRowsAffected dbColumnInfo dbHasCompleted dbGetInfo-methods > ### dbGetDBIVersion-methods dbGetStatement-methods dbGetRowCount-methods > ### dbGetRowsAffected-methods dbColumnInfo-methods dbHasCompleted-methods > ### dbGetInfo,DBIObject-method dbGetDBIVersion,-method > ### dbGetStatement,DBIResult-method dbGetRowCount,DBIResult-method > ### dbGetRowsAffected,DBIResult-method dbColumnInfo,DBIResult-method > ### dbHasCompleted,DBIResult-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D drv <- dbDriver("SQLite") > ##D con <- dbConnect(drv) > ##D > ##D dbListTables(con) > ##D > ##D rs <- dbSendQuery(con, query.sql) > ##D dbGetStatement(rs) > ##D dbHasCompleted(rs) > ##D > ##D info <- dbGetInfo(rs) > ##D names(dbGetInfo(drv)) > ##D > ##D # DBIConnection info > ##D names(dbGetInfo(con)) > ##D > ##D # DBIResult info > ##D names(dbGetInfo(rs)) > ## End(Not run) > > > > cleanEx(); ..nameEx <- "dbListTables-methods" > > ### * dbListTables-methods > > flush(stderr()); flush(stdout()) > > ### Name: dbListTables-methods > ### Title: List items from a remote DBMS and from objects that implement > ### the database interface DBI. > ### Aliases: dbListTables dbListFields dbListConnections dbListResults > ### dbListTables-methods dbListFields-methods dbListConnections-methods > ### dbListResults-methods dbListTables,DBIConnection-method > ### dbListFields,DBIConnection,character-method > ### dbListConnections,DBIDriver-method dbListResults,DBIConnection-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D drv <- dbDriver("RSQLite") > ##D # after working awhile... > ##D for(con in dbListConnections(odbc)){ > ##D dbGetStatement(dbListResults(con)) > ##D } > ## End(Not run) > > > > cleanEx(); ..nameEx <- "dbReadTable-methods" > > ### * dbReadTable-methods > > flush(stderr()); flush(stdout()) > > ### Name: dbReadTable-methods > ### Title: Convenience functions for Importing/Exporting DBMS tables > ### Aliases: dbReadTable dbWriteTable dbExistsTable dbRemoveTable > ### dbReadTable-methods dbWriteTable-methods dbExistsTable-methods > ### dbRemoveTable-methods dbReadTable,DBIConnection,character-method > ### dbWriteTable,DBIConnection,character,data.frame-method > ### dbExistsTable,DBIConnection,character-method > ### dbRemoveTable,DBIConnection,character-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D conn <- dbConnect("MySQL", group = "vitalAnalysis") > ##D con2 <- dbConnect("Oracle", username = "user", password = "pwd") > ##D if(dbExistsTable(con2, "fuel_frame")){ > ##D fuel.frame <- dbReadTable(con2, "fuel_frame") > ##D dbRemoveTable(conn, "fuel_frame") > ##D dbWriteTable(conn, "fuel_frame", fuel.frame) > ##D } > ##D if(dbExistsTable(conn, "RESULTS")){ > ##D dbWriteTable(conn, "RESULTS", results2000, append = T) > ##D else > ##D dbWriteTable(conn, "RESULTS", results2000) > ##D } > ## End(Not run) > > > > cleanEx(); ..nameEx <- "dbSendQuery-methods" > > ### * dbSendQuery-methods > > flush(stderr()); flush(stdout()) > > ### Name: dbSendQuery-methods > ### Title: Execute a statement on a given database connection > ### Aliases: dbSendQuery dbGetQuery dbClearResult dbGetException > ### dbSendQuery-methods dbGetQuery-methods dbClearResult-methods > ### dbGetException-methods dbSendQuery,DBIConnection,character-method > ### dbGetQuery,DBIConnection,character-method > ### dbClearResult,DBIResult-method dbGetException,DBIConnection-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D drv <- dbDriver("MySQL") > ##D con <- dbConnect(drv) > ##D res <- dbSendQuery(con, "SELECT * from liv25") > ##D data <- fetch(res, n = -1) > ## End(Not run) > > > > cleanEx(); ..nameEx <- "dbSetDataMappings-methods" > > ### * dbSetDataMappings-methods > > flush(stderr()); flush(stdout()) > > ### Name: dbSetDataMappings-methods > ### Title: Set data mappings between an DBMS and R/S-Plus > ### Aliases: dbSetDataMappings dbSetDataMappings-methods > ### dbSetDataMappings,DBIResult,data.frame-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D makeImage <- function(x) { > ##D .C("make_Image", as.integer(x), length(x)) > ##D } > ##D > ##D res <- dbSendQuery(con, statement) > ##D flds <- dbColumnInfo(res) > ##D flds[3, "Sclass"] <- makeImage > ##D > ##D dbSetDataMappings(rs, flds) > ##D > ##D im <- fetch(rs, n = -1) > ## End(Not run) > > > > cleanEx(); ..nameEx <- "fetch-methods" > > ### * fetch-methods > > flush(stderr()); flush(stdout()) > > ### Name: fetch-methods > ### Title: Fetch records from a previously executed query > ### Aliases: fetch fetch-methods fetch,DBIResult,numeric-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D # Run an SQL statement by creating first a resultSet object > ##D drv <- dbDriver("Oracle") > ##D con <- dbConnect(drv, ...) > ##D res <- dbSendQuery(con, statement = paste( > ##D "SELECT w.laser_id, w.wavelength, p.cut_off", > ##D "FROM WL w, PURGE P", > ##D "WHERE w.laser_id = p.laser_id", > ##D "ORDER BY w.laser_id")) > ##D # we now fetch the first 100 records from the resultSet into a data.frame > ##D data1 <- fetch(res, n = 100) > ##D dim(data1) > ##D > ##D dbHasCompleted(res) > ##D > ##D # let's get all remaining records > ##D data2 <- fetch(res, n = -1) > ## End(Not run) > > > > cleanEx(); ..nameEx <- "make.db.names-methods" > > ### * make.db.names-methods > > flush(stderr()); flush(stdout()) > > ### Name: make.db.names-methods > ### Title: Make R/S-Plus identifiers into legal SQL identifiers > ### Aliases: make.db.names SQLKeywords isSQLKeyword make.db.names-methods > ### SQLKeywords-methods isSQLKeyword-methods > ### make.db.names,DBIObject,character-method SQLKeywords,DBIObject-method > ### SQLKeywords,missing-method isSQLKeyword,DBIObject,character-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D # This example shows how we could export a bunch of data.frames > ##D # into tables on a remote database. > ##D > ##D con <- dbConnect("Oracle", user="iptraffic", pass = pwd) > ##D > ##D export <- c("trantime.email", "trantime.print", "round.trip.time.email") > ##D tabs <- make.db.names(export, unique = T, allow.keywords = T) > ##D > ##D for(i in seq(along = export) ) > ##D dbWriteTable(con, name = tabs[i], get(export[i])) > ##D > ##D # Oracle's extensions to SQL keywords > ##D oracle.keywords <- c("CLUSTER", "COLUMN", "MINUS", "DBNAME") > ##D isSQLKeyword(nam, c(.SQL92Keywords, oracle.keywords)) > ##D [1] T T T F > ## End(Not run) > > > > cleanEx(); ..nameEx <- "print.list.pairs" > > ### * print.list.pairs > > flush(stderr()); flush(stdout()) > > ### Name: print.list.pairs > ### Title: Support functions > ### Aliases: print.list.pairs print summary format > ### Keywords: interface database > > ### ** Examples > ## Not run: > ##D print.list.pairs(list(a =1, b = 2)) > ## End(Not run) > > > > ### *