Return the id column names(s) of a dataset if any. If not, the function returns a NULL object.
col_id(dataset)
A data frame object.
Name(s) of identifier column(s). NULL if not.
A dataset is a data table containing variables. A dataset object is a data frame and can be associated with a data dictionary. If no data dictionary is provided with a dataset, a minimum workable data dictionary will be generated as needed within relevant functions. Identifier variable(s) for indexing can be specified by the user. The id values must be non-missing and will be used in functions that require it. If no identifier variable is specified, indexing is handled automatically by the function.
{
# use madshapR_examples provided by the package
library(dplyr)
library(fabR)
###### Example 1: A dataset can have an id column specified as an attribute.
dataset <- as_dataset(madshapR_examples$`dataset_example`)
col_id(dataset)
dataset <- as_dataset(dataset, col_id = "part_id")
col_id(dataset)
###### Example 2: Any data frame can be a dataset by definition.
dataset <- tibble(iris %>% add_index("my_index"))
dataset <- as_dataset(dataset, "my_index")
col_id(dataset)
}
#> [1] "my_index"