Skip to content

Commit

Permalink
- as_fileMDB
Browse files Browse the repository at this point in the history
- relational_tables for metaMDB
- improve documentation
  • Loading branch information
patzaw committed Aug 28, 2020
1 parent ad868f2 commit f6893d2
Show file tree
Hide file tree
Showing 27 changed files with 309 additions and 241 deletions.
8 changes: 5 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ S3method("names<-",fileMDB)
S3method("names<-",memoMDB)
S3method("names<-",metaMDB)
S3method(as.list,MDB)
S3method(as_fileMDB,fileMDB)
S3method(as_fileMDB,memoMDB)
S3method(as_fileMDB,metaMDB)
S3method(c,fileMDB)
S3method(c,memoMDB)
S3method(c,metaMDB)
Expand Down Expand Up @@ -63,13 +66,12 @@ S3method(slice,fileMDB)
S3method(slice,memoMDB)
S3method(slice,metaMDB)
S3method(str,MDB)
S3method(write_MDB,fileMDB)
S3method(write_MDB,memoMDB)
export("collection_members<-")
export("db_info<-")
export(MDBs)
export(add_chMDB_user)
export(add_chTKCat_collection)
export(as_fileMDB)
export(as_memoMDB)
export(chTKCat)
export(ch_insert)
Expand Down Expand Up @@ -116,10 +118,10 @@ export(metaMDB)
export(read_collection_members)
export(read_fileMDB)
export(reconnect_chTKCat)
export(relational_tables)
export(remove_chMDB_user)
export(remove_chTKCat_collection)
export(set_chMDB_access)
export(write_MDB)
export(write_MergeTree)
export(write_collection_members)
import(DBI)
Expand Down
2 changes: 1 addition & 1 deletion R/MDB.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#'
#' @seealso MDB methods:
#' [db_info], [data_model], [data_tables], [collection_members],
#' [count_records], [filter_with_tables], [write_MDB]
#' [count_records], [filter_with_tables], [as_fileMDB]
#' Additional documentation is provided for each specific class:
#' [fileMDB], [memoMDB], chMDB and [metaMDB].
#'
Expand Down
59 changes: 8 additions & 51 deletions R/fileMDB.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' @seealso
#' - MDB methods:
#' [db_info], [data_model], [data_tables], [collection_members],
#' [count_records], [filter_with_tables], [write_MDB]
#' [count_records], [filter_with_tables], [as_fileMDB]
#' - Additional general documentation is related to [MDB].
#' - [filter.fileMDB], [slice.fileMDB]
#'
Expand Down Expand Up @@ -296,11 +296,10 @@ is.fileMDB <- function(x){


###############################################################################@
#' Rename tables of a [fileMDB] object
#'
#' @param .data a fileMDB
#' @param .data a [fileMDB] object
#' @param ... Use new_name = old_name to rename selected tables
#'
#' @rdname fileMDB
#'
#' @export
#'
Expand All @@ -313,8 +312,6 @@ rename.fileMDB <- function(.data, ...){


###############################################################################@
#' @param x a [fileMDB] object
#' @param ... not used
#'
#' @rdname db_info
#' @method db_info fileMDB
Expand All @@ -329,10 +326,6 @@ db_info.fileMDB <- function(x, ...){


###############################################################################@
#' @param x a [fileMDB] object
#' @param value a list with DB information:
#' "name", "title", "description", "url",
#' "version", "maintainer".
#'
#' @rdname db_info
#' @method db_info<- fileMDB
Expand All @@ -352,8 +345,6 @@ db_info.fileMDB <- function(x, ...){


###############################################################################@
#' @param x a [fileMDB] object
#' @param ... not used
#'
#' @rdname data_model
#' @method data_model fileMDB
Expand All @@ -366,9 +357,6 @@ data_model.fileMDB <- function(x, ...){


###############################################################################@
#' @param x a [fileMDB] object
#' @param ... names of the collections
#' to focus on. By default, all of them are taken.
#'
#' @rdname collection_members
#' @method collection_members fileMDB
Expand All @@ -391,21 +379,7 @@ collection_members.fileMDB <- function(


###############################################################################@
#' @param x a [fileMDB] object
#'
#' @param value A data.frame with the following columns:
#' - **collection** (character): The name of the collection
#' - **cid** (character): Collection identifier
#' - **resource** (character): The name of the resource
#' - **mid** (integer): The identifier of the member
#' - **table** (character): The table recording collection information
#' - **field** (character): The collection field.
#' - **static** (logical): TRUE if the field value is common to all elements.
#' - **value** (character): The name of the table column if static is FALSE
#' or the field value if static is TRUE.
#' - **type** (character): the type of the field.
#' (not necessarily used ==> NA if not)
#'
#'
#' @rdname collection_members
#' @method collection_members<- fileMDB
#'
Expand Down Expand Up @@ -476,8 +450,6 @@ collection_members.fileMDB <- function(


###############################################################################@
#' @param x a [fileMDB] object
#' @param ... the name of the tables to get (default: all of them)
#'
#' @rdname data_tables
#' @method data_tables fileMDB
Expand Down Expand Up @@ -510,8 +482,6 @@ data_tables.fileMDB <- function(x, ...){


###############################################################################@
#' @param x a [fileMDB]
#' @param ... the name of the tables to consider (default: all of them)
#'
#' @rdname count_records
#' @method count_records fileMDB
Expand Down Expand Up @@ -696,16 +666,13 @@ c.fileMDB <- function(...){


###############################################################################@
#' @param x a [fileMDB]
#' @param path the path where the MDB should be written
#' @param ... not used
#'
#' @rdname write_MDB
#' @method write_MDB fileMDB
#' @rdname as_fileMDB
#' @method as_fileMDB fileMDB
#'
#' @export
#'
write_MDB.fileMDB <- function(x, path, ...){
as_fileMDB.fileMDB <- function(x, path, ...){
stopifnot(is.character(path), length(path)==1, !is.na(path))
dbInfo <- db_info(x)
dbName <- dbInfo$name
Expand Down Expand Up @@ -734,7 +701,7 @@ write_MDB.fileMDB <- function(x, path, ...){

## Collection members ----
cm <- collection_members(x)
if(nrow(cm)>0){
if(!is.null(cm) && nrow(cm)>0){
colPath <- file.path(modelPath, "Collections")
dir.create(colPath)
for(collection in unique(cm$collection)){
Expand Down Expand Up @@ -858,16 +825,6 @@ slice.fileMDB <- function(.data, ..., .preserve=FALSE){


###############################################################################@
#' Filter [fileMDB] object according to provided tables
#'
#' @param x a [fileMDB] object
#' @param tables a named list of tibbles to filter with. The names should
#' correspond to the table names in x and the tibbles should fit the
#' data model.
#' @param checkTables if TRUE, the tables are confronted to their model
#' in the data model of x.
#'
#' @return a [memoMDB] object
#'
#' @rdname filter_with_tables
#' @method filter_with_tables fileMDB
Expand Down
15 changes: 11 additions & 4 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#' DB information
#'
#' @param x an object with embedded database information
#' @param ... method specific parameters
#'
#' @return A list with the following elements:
#' - **name**: a single character
Expand Down Expand Up @@ -45,6 +46,7 @@ db_info <- function(x, ...){
#' Get object data model
#'
#' @param x an object with an embedded data model
#' @param ... method specific parameters
#'
#' @return A [ReDaMoR::RelDataModel] object
#'
Expand All @@ -59,6 +61,8 @@ data_model <- function(x, ...){
#' Collection members
#'
#' @param x an object with embedded collection members
#' @param ... names of the collections
#' to focus on. By default, all of them are taken.
#'
#' @return A [tibble::tibble] with the following columns:
#' - **collection** (character): The name of the collection
Expand Down Expand Up @@ -109,6 +113,7 @@ collection_members <- function(x, ...){
#' Get object data tables
#'
#' @param x an object with embedded data tables
#' @param ... the name of the tables to get (default: all of them)
#'
#' @return A list of [dplyr::tibble]
#'
Expand All @@ -123,6 +128,7 @@ data_tables <- function(x, ...){
#' Count the number of records
#'
#' @param x an object with embedded data tables
#' @param ... the name of the tables to consider (default: all of them)
#'
#' @return A named vector with the number of records per table.
#'
Expand All @@ -134,9 +140,9 @@ count_records <- function(x, ...){


###############################################################################@
#' Filter an MDB object according to provided tables
#' Filter an [MDB] object according to provided tables
#'
#' @param x an MDB object
#' @param x an [MDB] object
#' @param tables a named list of tibbles to filter with. The names should
#' correspond to the table names in x and the tibbles should fit the
#' data model.
Expand All @@ -158,13 +164,14 @@ filter_with_tables <- function(x, tables, checkTables=TRUE){
#'
#' @param x an MDB object
#' @param path the path where the MDB should be written
#' @param ... method specific parameters
#'
#' @return A [fileMDB] object.
#'
#' @export
#'
write_MDB <- function(x, path, ...){
UseMethod("write_MDB", x)
as_fileMDB <- function(x, path, ...){
UseMethod("as_fileMDB", x)
}


Expand Down
Loading

0 comments on commit f6893d2

Please sign in to comment.