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("RSQLite-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('RSQLite') Loading required package: DBI > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "SQLite" > > ### * SQLite > > flush(stderr()); flush(stdout()) > > ### Name: SQLite > ### Title: Instantiate the SQLite engine from the current R session. > ### Aliases: SQLite SQLiteDriver > ### Keywords: interface database > > ### ** Examples > ## Not run: > ##D # create a SQLite instance and create one connection. > ##D m <- dbDriver("SQLite") > ##D > ##D # initialize a new database "base.dbms" in the current directory > ##D # and copy some data.frame from the base package into it > ##D > ##D con <- dbConnect(m, dbname = "base.dbms") > ##D data(USArrests) > ##D dbWriteTable(con, "USArrests", USArrests, overwrite = T) > ##D > ##D # query > ##D rs <- dbSendQuery(con, "select * from USArrests") > ##D d1 <- fetch(rs, n = 10) # extract data in chunks of 10 rows > ##D dbHasCompleted(rs) > ##D d2 <- fetch(rs, n = -1) # extract all remaining data > ##D dbHasCompleted(rs) > ##D dbClearResult(rs) > ##D dbListTables(con) > ##D > ## End(Not run) > > > > cleanEx(); ..nameEx <- "SQLiteConnection-class" > > ### * SQLiteConnection-class > > flush(stderr()); flush(stdout()) > > ### Name: SQLiteConnection-class > ### Title: Class SQLiteConnection > ### Aliases: SQLiteConnection-class > ### Keywords: database interface classes > > ### ** Examples > ## Not run: > ##D drv <- dbDriver("SQLite") > ##D con <- dbConnect(drv, dbname = "rsdbi.db") > ## End(Not run) > > > > cleanEx(); ..nameEx <- "SQLiteDriver-class" > > ### * SQLiteDriver-class > > flush(stderr()); flush(stdout()) > > ### Name: SQLiteDriver-class > ### Title: Class SQLiteDriver > ### Aliases: SQLiteDriver-class > ### Keywords: database interface classes > > ### ** Examples > ## Not run: > ##D drv <- dbDriver("SQLite") > ##D con <- dbConnect(drv, "user/password@dbname") > ## End(Not run) > > > > cleanEx(); ..nameEx <- "SQLiteObject-class" > > ### * SQLiteObject-class > > flush(stderr()); flush(stdout()) > > ### Name: SQLiteObject-class > ### Title: Class SQLiteObject > ### Aliases: SQLiteObject-class > ### Keywords: database interface classes > > ### ** Examples > ## Not run: > ##D drv <- dbDriver("SQLite") > ##D con <- dbConnect(drv, dbname = "rsdbi.db") > ## End(Not run) > > > > cleanEx(); ..nameEx <- "SQLiteResult-class" > > ### * SQLiteResult-class > > flush(stderr()); flush(stdout()) > > ### Name: SQLiteResult-class > ### Title: Class SQLiteResult > ### Aliases: SQLiteResult-class > ### Keywords: database interface classes > > ### ** Examples > ## Not run: > ##D drv <- dbDriver("SQLite") > ##D con <- dbConnect(drv, dbname = "rsdbi.db") > ## End(Not run) > > > > cleanEx(); ..nameEx <- "dbCommit-methods" > > ### * dbCommit-methods > > flush(stderr()); flush(stdout()) > > ### Name: dbCommit-methods > ### Title: DBMS Transaction Management > ### Aliases: dbCommit-methods dbRollback-methods > ### dbCommit,SQLiteConnection-method dbRollback,SQLiteConnection-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D drv <- dbDriver("SQLite") > ##D con <- dbConnect(drv, dbname = "mySQLite.db") > ##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 object to an SQLite DBMS > ### Aliases: dbDisconnect-methods dbConnect-methods > ### dbDisconnect,SQLiteConnection-method dbConnect,SQLiteDriver-method > ### dbConnect,SQLiteConnection-method dbConnect,character-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D # create an SQLite instance and create one connection. > ##D drv <- dbDriver("SQLite") > ##D > ##D # open the connection using user, passsword, etc., as > ##D con <- dbConnect(drv, dbname = "sqlite.db") > ##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-methods dbDataType,SQLiteObject-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D data(quakes) > ##D drv <- dbDriver("SQLite") > ##D sql.type <- dbDataType(drv, quakes) > ## End(Not run) > > > > cleanEx(); ..nameEx <- "dbDriver-methods" > > ### * dbDriver-methods > > flush(stderr()); flush(stdout()) > > ### Name: dbDriver-methods > ### Title: SQLite implementation of the Database Interface (DBI) classes > ### and drivers > ### Aliases: dbDriver-methods dbUnloadDriver-methods > ### dbDriver,character-method dbUnloadDriver,SQLiteDriver-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D # create an SQLite instance for capacity of up to 25 simultaneous > ##D # connections. > ##D m <- dbDriver("SQLite", max.con = 25) > ##D > ##D con <- dbConnect(m, dbname="sqlite.db") > ##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-methods dbGetStatement-methods > ### dbGetRowCount-methods dbGetRowsAffected-methods dbColumnInfo-methods > ### dbHasCompleted-methods dbGetInfo,SQLiteObject-method > ### dbGetInfo,SQLiteDriver-method dbGetInfo,SQLiteConnection-method > ### dbGetInfo,SQLiteResult-method dbGetStatement,SQLiteResult-method > ### dbGetRowCount,SQLiteResult-method > ### dbGetRowsAffected,SQLiteResult-method > ### dbColumnInfo,SQLiteResult-method dbHasCompleted,SQLiteResult-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 an SQLite DBMS and from objects > ### Aliases: dbListTables-methods dbListFields-methods > ### dbListConnections-methods dbListResults-methods > ### dbListTables,SQLiteConnection-method > ### dbListFields,SQLiteConnection,character-method > ### dbListConnections,SQLiteDriver-method > ### dbListResults,SQLiteConnection-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D drv <- dbDriver("SQLite") > ##D # after working awhile... > ##D for(con in dbListConnections(odbc)){ > ##D dbGetStatement(dbListResults(con)) > ##D } > ## End(Not run) > > > > cleanEx(); ..nameEx <- "dbObjectId-class" > > ### * dbObjectId-class > > flush(stderr()); flush(stdout()) > > ### Name: dbObjectId-class > ### Title: Class dbObjectId > ### Aliases: dbObjectId-class > ### Keywords: classes > > ### ** Examples > ## Not run: > ##D pg <- dbDriver("PostgreSQL") > ##D con <- dbConnect(pg, "user", "password") > ##D is(pg, "dbObjectId") ## True > ##D is(con, "dbObjectId") ## True > ##D isIdCurrent(con) ## True > ##D q("yes") > ##D \$ R > ##D isIdCurrent(con) ## False > ## 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-methods dbWriteTable-methods dbExistsTable-methods > ### dbRemoveTable-methods dbReadTable,SQLiteConnection,character-method > ### dbWriteTable,SQLiteConnection,character,data.frame-method > ### dbExistsTable,SQLiteConnection,character-method > ### dbRemoveTable,SQLiteConnection,character-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D conn <- dbConnect("SQLite", dbname = "sqlite.db") > ##D if(dbExistsTable(con, "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-methods dbGetQuery-methods dbClearResult-methods > ### dbGetException-methods dbSendQuery,SQLiteConnection,character-method > ### dbGetQuery,SQLiteConnection,character-method > ### dbClearResult,SQLiteResult-method > ### dbGetException,SQLiteConnection-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 SQLite and R/S-Plus > ### Aliases: dbSetDataMappings-methods > ### dbSetDataMappings,SQLiteResult,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-methods fetch,SQLiteResult,numeric-method > ### fetch,SQLiteResult-method > ### Keywords: interface interface database > > ### ** Examples > ## Not run: > ##D drv <- dbDriver("SQLite") > ##D con <- dbConnect(drv, dbname = "sqlite.db") > ##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 <- "isIdCurrent" > > ### * isIdCurrent > > flush(stderr()); flush(stdout()) > > ### Name: isIdCurrent > ### Title: Check whether an dbObjectId handle object is valid or not > ### Aliases: isIdCurrent > ### Keywords: interface database > > ### ** Examples > ## Not run: > ##D cursor <- dbSendQuery(con, sql.statement) > ##D isIdCurrent(cursor) > ## 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: SQLKeywords-methods isSQLKeyword-methods > ### make.db.names,SQLiteObject,character-method > ### SQLKeywords,SQLiteObject-method SQLKeywords,missing-method > ### isSQLKeyword,SQLiteObject,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("SQLite", dbname = "sqlite.db") > ##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])) > ## End(Not run) > > > > cleanEx(); ..nameEx <- "safe.write" > > ### * safe.write > > flush(stderr()); flush(stdout()) > > ### Name: safe.write > ### Title: Write a data.frame avoiding exceeding memory limits > ### Aliases: safe.write > ### Keywords: internal > > ### ** Examples > ## Not run: > ##D ctr.file <- file("dump.sqloader", "w") > ##D safe.write(big.data, file = ctr.file, batch = 25000) > ## End(Not run) > > > > ### *