discover_keys: Key discovery with MCSS

View source: R/discover_keys.r

discover_keysR Documentation

Key discovery with MCSS

Description

Finds all the keys for a data frame, ignoring duplicate rows.

Usage

discover_keys(
  df,
  keep_rownames = FALSE,
  digits = getOption("digits"),
  exclude = character(),
  exclude_class = character(),
  size_limit = ncol(df),
  progress = FALSE,
  progress_file = "",
  skip_bijections = FALSE
)

Arguments

df

a data.frame, the relation to evaluate.

keep_rownames

a logical or a string, indicating whether to include the row names as a column. If a string is given, it is used as the name for the column, otherwise the column is named "row". Like with the other column names, the function returns an error if this results in duplicate column names. Set to FALSE by default.

digits

a positive integer, indicating how many significant digits are to be used for numeric and complex variables. A value of NA results in no rounding. By default, this uses getOption("digits"), similarly to format. See the "Floating-point variables" section for discover for why this rounding is necessary for consistent results across different machines. See the note in print.default about digits >= 16.

exclude

a character vector, containing names of attributes to not consider as members of keys. If names are given that aren't present in df, the user is given a warning.

exclude_class

a character vector, indicating classes of attributes to not consider as members of keys. Attributes are excluded if they inherit from any given class.

size_limit

an integer, indicating the largest key size to search for. By default, this is large enough to allow all attributes.

progress

a logical, for whether to display progress to the user during dependency search in discover.

progress_file

a scalar character or a connection. If progress is non-zero, determines where the progress is written to, in the same way as the file argument for cat.

skip_bijections

a logical, indicating whether to skip some key searches that are made redundant by discovered bijections between attributes. This can significantly speed up the search. See Details in the documentation for discover for more information.

Details

Column names for df must be unique.

The search algorithm was adapted from the FDHits algorithm used for discover. It is likely to be an implementation of the HPIValid algorithm, although it wasn't used directly as a source. It has the same implications with respect to floating-point variables.

Value

A list of character vectors, containing the discovered keys. The attributes within each key are given in the same order as in df.

References

FDHits: Bleifuss T., Papenbrock T., Bläsius T., Schirneck M, Naumann F. (2024) Discovering Functional Dependencies through Hitting Set Enumeration. Proc. ACM Manag. Data, 2, 1, 43:1–24.

HPIValid: Birnick J., Bläsius T., Friedrich T., Naumann F., Papenbrock T., Schirneck M. (2020) Hitting set enumeration with partial information for unique column combination discovery. Proceedings of the VLDB Endowment, 13, 12, 2270–2283.

Examples

# simple example
discover_keys(ChickWeight)

# example with spurious key
discover_keys(CO2)
# exclude attributes that can't be determinants.
# in this case, the numeric attributes are now
# not determined by anything, because of repeat measurements
# with no variable to mark them as such.
discover_keys(CO2, exclude_class = "numeric")
# exclude keys spuriously using the measurement attribute
discover_keys(CO2, exclude = "uptake")

autodb documentation built on Aug. 4, 2026, 1:08 a.m.