opm_dbput {opmextra}R Documentation

Database I/O for opm


Methods for inserting, querying and deleting OPMX objects into or from (SQL-based) relational databases using RODBC.


  ## S4 method for signature 'integer,RODBC'
opm_dbclear(object, conn, map.tables = NULL, klass = "OPM_DB")

  ## S4 method for signature 'character,RODBC'
opm_dbfind(object, conn, map.tables = NULL, klass = "OPM_DB")

  ## S4 method for signature 'integer,RODBC'
opm_dbget(object, conn,
    map.tables = NULL, include = 2L, klass = c(opm_dbclass(include), "MOPMX")) 

  ## S4 method for signature 'DBTABLES,RODBC'
opm_dbnext(object, conn, map.tables = NULL)

  ## S4 method for signature 'DBTABLES,RODBC'
opm_dbput(object, conn,
    map.tables = NULL, start = opm_dbnext(object, conn, map.tables)) 



OPMX, MOPMX or OPM_DB object, integer vector containing real or potential primary keys of a database table, or character scalar containing a partial SQL query (the part after the ‘WHERE’ keyword).


Database connection object. RODBC objects as created by the RODBC package are supported.


Passed as do_map argument to by from the pkgutils package. Necessary if table names that deviate from the defaults are to be used.


Character vector indicating one or several class names. For PM data this argument should not be changed.


Integer scalar indicating whether aggregated data (1) or aggregated and discretised data (2) or neither (0) should be added to the result. The numeric method of opm_dbnext needs the same kind of object argument.


Integer vector determining the minimum primary keys to which those in object should be coerced. Necessary for appending to a database table without overwriting previously inserted data.


Optional arguments passed between the methods.


The RODBC methods use a simple quoting scheme for table and column names.

Note that the deletion mechanism is based on ON DELETE CASCADE. To enable this in SQLite, PRAGMA foreign_keys = ON; has to be called each time a database is opened. See the according demo entry.


The main functions are those for create, search, read and delete operations:

Regarding the helper functions, opm_dbnext returns an integer scalar that is suitable as start argument of opm_dbput, whereas opm_dbclass returns a character scalar with the name of the intermediary class (derived from OPM_DB) to be created for database I/O. These need not normally be called by an opm user.

For checking whether a database (connection) is correctly set up, opm_dbcheck is available in the opm package, which returns a character vector whose elements are either ok or a description of the error that has occurred at that step of the checking process.

See Also

DBI::make.db.names pkgutils::by opm::opm_dbcheck

Other res: cor.test


# The SQL files for generating the expected database tables. Tables can
# be renamed, but then an according 'map.tables' argument must be used.
## [1] "/usr/local/lib/R/library/opm/auxiliary/001_rdbms_drop.sql"  
## [2] "/usr/local/lib/R/library/opm/auxiliary/002_rdbms_create.sql"
## [3] "/usr/local/lib/R/library/opm/auxiliary/003_rdbms_delete.sql"
# Usage examples are given in these demos. An according database must be
# made accessible beforehand.
if (interactive())
  demo(package = "opmextra")

[Package opmextra version 0.0.10 Index]