Finds all the keys for a data frame, ignoring duplicate rows.
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
NAresults in no rounding. By default, this usesgetOption("digits"), similarly toformat. See the "Floating-point variables" section fordiscoverfor why this rounding is necessary for consistent results across different machines. See the note inprint.defaultaboutdigits >= 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
progressis non-zero, determines where the progress is written to, in the same way as thefileargument forcat.- 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
discoverfor more information.
Value
A list of character vectors, containing the discovered keys. The
attributes within each key are given in the same order as in df.
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.
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)
#> [[1]]
#> [1] "Time" "Chick"
#>
# example with spurious key
discover_keys(CO2)
#> [[1]]
#> [1] "Treatment" "conc" "uptake"
#>
#> [[2]]
#> [1] "Plant" "conc"
#>
# 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")
#> list()
# exclude keys spuriously using the measurement attribute
discover_keys(CO2, exclude = "uptake")
#> [[1]]
#> [1] "Plant" "conc"
#>