guess_constraints | R Documentation |
Guess RelDataModel constraints based on the provided or existing tables
guess_constraints(
x,
data = NULL,
env = parent.frame(n = 1),
constraints = c("unique", "not nullable", "foreign keys")
)
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 |
The guessed constraints should be carefully review, especially the foreign keys.
Complex foreign keys involving multiple fields are not guessed.
A RelDataModel
## 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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.