Learn R Programming

ReDaMoR (version 0.8.2)

guess_constraints: Guess RelDataModel constraints based on the provided or existing tables

Description

Guess RelDataModel constraints based on the provided or existing tables

Usage

guess_constraints(
  x,
  data = NULL,
  env = parent.frame(n = 1),
  constraints = c("unique", "not nullable", "foreign keys")
)

Value

A RelDataModel

Arguments

x

a RelDataModel

data

a named list of tables. All names of x should exist in data. If NULL, the data are taken from env.

env

the R environment in which to find the tables

constraints

the type of constraints to guess

Details

The guessed constraints should be carefully review, especially the foreign keys.

Complex foreign keys involving multiple fields are not guessed.

Examples

Run this code
## Read data files ----
to_read <- list.files(
   system.file("examples/HPO-subset", package="ReDaMoR"),
   full.names=TRUE
)
hpo_tables <- list()
for(f in to_read){
   hpo_tables[[sub("[.]txt$", "", basename(f))]] <- readr::read_tsv(f)
}
## Build the model from a list of data frames ----
new_model <- df_to_model(
   list=names(hpo_tables), envir=as.environment(hpo_tables)
)
## Guess constraints and auto layout ----
new_model <- guess_constraints(new_model, data = hpo_tables) %>%
   auto_layout(lengthMultiplier=250)

## Plot the model ----
new_model %>%
   plot()

Run the code above in your browser using DataLab