tabde: tabde: Define and Check The Structure of Data Frames and...

Description Usage Arguments Value Database constraints Storing table_designs Author(s) See Also Examples

View source: R/tabde.R

Description

Define the structure (column names and types) of tables and save them as csv files. Tools are provided to use such table design to create database tables, read fwf and csv files, and check data.frames for validity.

Table designs are data.frames that contain meta-info on other data.frames such as column names and types. Such table_designs can be used for validating the structure of data.frames, generating SQL code, reading files, etc...

Usage

 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
tabde(
  col_name,
  col_type = rep(NA_character_, length(col_name)),
  col_domain = NULL,
  ...
)

tabde_fwf(
  col_name,
  col_type = rep(NA_character_, length(col_name)),
  fwf_start,
  fwf_end,
  col_domain = NULL,
  ...
)

tabde_sql(
  col_name,
  col_type = rep(NA_character_, length(col_name)),
  sql_type = rep(NA_character_, length(col_name)),
  sql_opts = rep(NA_character_, length(col_name)),
  col_domain = NULL,
  ...,
  .sql_header = NULL
)

Arguments

col_name

character vector. column names

col_type

character vector. Valid data.frame column types. NAs and the string "#skip" have special meanings.

NAs will be converted to readr::col_guess() by as_col_spec() and matches_tabde() will not check the classes of NA columns. In a similar fashion #skip columns will be converted to readr::col_skip() and matches_tabde will not check if they are present in dat or not.

col_domain

character vector. A valid domain for col_name. Domains can be used by matches_tabde() and as_sql() to check for valid (discrete) values if a values Object is passed to these functions.

...

passed on to methods

fwf_start

integer vector. fwf start positions

fwf_end

integer vector. fwf end positions

sql_type

character vector. SQL Data Types as supported by target DBMS System. Columns with col_type NA will be skipped when creating SQL statements.

sql_opts

character vector. SQL Options to be used by as_sql() (for example NOT NULL)

.sql_header

a sql_header() data.frame

Value

a data.frame of class table_design

Database constraints

A table design can contain a sql_header() object that represents database constraints (such as primary key) as the attribute 'sql_header'. If such an attribute is present, as_sql() will use it when transforming a table design to an SQL CREATE TABLE statement.

Storing table_designs

table_desings are designed to be stored as .csv files. This has some disadvantages over storing them in a binary format such as .rds or .rda, but makes it easy to edit them and track changes in a VCS such as git.

Author(s)

Maintainer: Stefan Fleck stefan.b.fleck@gmail.com

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
tabde_sql(
   col_name = c("first_name", "last_name", "age"),
   col_type = c("character", "character", "integer"),
   sql_type = c("varchar(255)", "varchar(255)", "integer"),
    .sql_header = sql_header(
      "person_pk",
      "primary key",
      list(c("first_name", "last_name"))
    )
 )

s-fleck/tabde documentation built on April 4, 2021, 10:11 p.m.