OPM_DB: Classes for 'opm' database I/O

Description Details See Also Examples

Description

These child classes of DBTABLES from the pkgutils package hold intermediary objects that can be used for database input and output of OPMX objects. These classes are not normally directly dealt with by an opm user but are documented here for completeness. See opm_dbput for methods that internally use these classes for database I/O.

Details

See their documentation for details on OPMX objects themselves. We here define the following additional classes:

OPM_DB

Holds all data that occur in an OPM object, or in several such objects as contained in an OPMS object.

OPMA_DB

Holds all data that occur in an OPMA object, or in several such objects as contained in an OPMS object.

OPMD_DB

Holds all data that occur in an OPMD object, or in several such objects as contained in an OPMS object.

The inheritance relationships thus mirror those of the OPMX objects (with the exception of OPMS). Conversion with as is implemented from all OPMX classes to all classes defined here. Lists can also be converted provided they only contain OPMX objects (or lists of such objects).

Conversion in the other direction, yielding one of the OPMX classes, is also implemented. Attempting to convert several plates to an OPMX class other than OPMS will yield an error, however, as well as trying to convert a single plate to OPMS, or several plates with distinct plate types. In contrast, conversion to a list will work in all instances, and such a list could further be processed with the opms function, irrespective of the number of plates contained.

In contrast to the OPMX classes, the three ones defined here can be created using new, yielding empty objects. These can neither be converted to OPMX objects nor combined with them using c. Instead, they are useful in conjunction with by from the pkgutils package with do_inline set to TRUE. They contain all fkeys information and can be filled using a suitable FUN argument.

See Also

methods::Methods methods::new opm::opms

Other classes: FOE, MOPMX, OPM, OPMA, OPMD, OPMS, OPMX, OPM_MCP_OUT, WMD, WMDS, WMDX, XOPMX, YAML_VIA_LIST

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
library(pkgutils)

## overview on the classes
showClass("OPM_DB")
showClass("OPMA_DB")
showClass("OPMD_DB")

## show all conversions with as()
showMethods("coerce", classes = c("OPM_DB", "OPMA_DB", "OPMD_DB"))

## conversions back and forth, OPMD as starting point
(x <- as(vaas_1, "OPMD_DB"))
(y <- as(x, "OPMD"))
stopifnot(
  dim(y) == dim(vaas_1),
  # numeric data remain except for rounding errors:
  all.equal(measurements(y), measurements(vaas_1)),
  all.equal(aggregated(y), aggregated(vaas_1)),
  all.equal(discretized(y), discretized(vaas_1)),
  # file names get normalized, hence CSV dat may get unequal:
  !isTRUE(all.equal(csv_data(y), csv_data(vaas_1)))
)
(y <- try(as(x, "OPMS"), silent = TRUE))
stopifnot(inherits(y, "try-error")) # does not work because only 1 plate

## conversions back and forth, OPMS as starting point
(small <- vaas_4[, , 11:15])
(x <- as(small, "OPMD_DB"))
(y <- as(x, "OPMS"))
stopifnot(sapply(1:length(y), # same values
  function(i) dim(y[i]) == dim(small[i])))
(y <- try(as(x, "OPMD"), silent = TRUE)) # does not work because > 1 plate
stopifnot(inherits(y, "try-error"))
(y <- as(x, "list")) # one can always go through a list
stopifnot(sapply(y, is, "OPMD")) # opms() could now be called

## one can create new objects without data
(y <- new("OPMD_DB"))
stopifnot(fkeys_valid(y), fkeys(y) == fkeys(x), !length(y))
# such objects cannot be converted to OPMX but can be filled using by()

opm documentation built on May 2, 2019, 6:08 p.m.