Functions for getting information about keys.

keys(.tbl)

raw_keys(.tbl)

has_keys(.tbl)

Arguments

.tbl

Reference data frame.

Value

keys() always returns a tibble of keys. In case of no keys it returns a tibble with number of rows as in .tbl and zero columns. raw_keys() is just a wrapper for attr(.tbl, "keys"). To know whether .tbl has keys use has_keys().

Examples

keys(mtcars)
#> # A tibble: 32 × 0

raw_keys(mtcars)
#> NULL

has_keys(mtcars)
#> [1] FALSE

df <- key_by(mtcars, vs, am)
keys(df)
#> # A tibble: 32 × 2
#>       vs    am
#>    <dbl> <dbl>
#>  1     0     1
#>  2     0     1
#>  3     1     1
#>  4     1     0
#>  5     0     0
#>  6     1     0
#>  7     0     0
#>  8     1     0
#>  9     1     0
#> 10     1     0
#> # … with 22 more rows

has_keys(df)
#> [1] TRUE