read a generalisation hierarchy from a CSV or YAML file
Source:R/generalize.R
read_generalization_hierarchy.Rd**CSV** is the long edge list [generalization_hierarchy()] takes, one edge per row:
Usage
read_generalization_hierarchy(path, format = c("auto", "csv", "yaml"))Details
“` attribute,value,parent AREA,chiyoda,tokyo AREA,tokyo,kanto AGE,"[30,35)","[30,40)" “`
**YAML** is the same tree written as nesting, which is easier to keep correct by hand:
“` AREA: kanto: tokyo: [chiyoda, shinjuku] kanagawa: [yokohama] AGE: "[30,40)": ["[30,35)", "[35,40)"] “`
YAML needs the `yaml` package, which is a **Suggests**, not a hard dependency: CSV covers the same ground with nothing extra installed. If `yaml` is missing this stops with a message saying so rather than guessing.
See also
[generalization_hierarchy()] to build one in memory, and the example files in `system.file("extdata", package = "reidentify")`.
Examples
p <- system.file("extdata", "generalization-jp.csv", package = "reidentify")
if (nzchar(p)) read_generalization_hierarchy(p)
#> generalization hierarchy: 50 edge(s) over 2 attribute(s)
#> AREA: 30 edge(s), 3 level(s), root(s): 関東, 近畿, 中部
#> AGE: 20 edge(s), 2 level(s), root(s): [0,10), [10,20), [20,30), [30,40), [40,50)