Skip to contents

This is a wrapper function for applying discover_keys, relation_schema, create, and insert. This takes a data frame and adds its keys, resulting in a single relation. If only the keys are required, this can be much quicker than running autodb.

Usage

autokey(
  df,
  keep_rownames = FALSE,
  digits = getOption("digits"),
  progress = FALSE,
  progress_file = "",
  ...
)

Arguments

df

a data.frame, containing the data to be normalised.

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. This is used for both pre-formatting in discover_keys, and for rounding the data before use in insert, so that the data satisfies the resulting schema. 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.

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.

...

further arguments passed on to discover_keys.

Value

A relation of length 1, containing the data in df and its keys.

Examples

# simple example
autokey(ChickWeight)
#> 1 relation
#> 4 attributes: weight, Time, Chick, Diet
#> relation data: Time, Chick, weight, Diet; 578 records
#>   key 1: Time, Chick