This function creates a nested sdc hierarchy from various input structures.
hier_import(inp, from = "json", root = NULL, keep_order = FALSE)
an object that should be imported. Argument from
specifies
the input format.
(character) from which format should be imported. Possible choices are:
"json"
: a json-encoded string as created using
hier_convert()
with argument as = "json")
"df"
: a data.frame
in @;level
-format or an input created
with hier_convert()
with argument as = "df")
"dt"
: a data.frame
in @;level
-format or an input created
with hier_convert()
with argument as = "dt")
"argus"
: a json-encoded string as created using
hier_convert()
with argument as = "argus")
"code"
: a json-encoded string as created using
hier_convert()
with argument as = "code")
"hrc"
: text-files in tau-argus hrc-format
"sdc"
: a json-encoded string as created using
hier_convert()
with argument as = "sdc")
optional name of overall total
if TRUE
, the original order of nodes
is kept from the input object; if FALSE
, the nodes are
sorted lexicographically within each leaf.
a (nested) hierarchy
h <- hier_create(root = "Total", nodes = LETTERS[1:2])
h <- hier_add(h, root = "A", nodes = c("a1", "a2"))
h <- hier_add(h, root = "B", nodes = c("b1", "b2"))
h <- hier_add(h, root = "b1", nodes = "b1a")
hier_display(h)
#> Total
#> ├─A
#> │ ├─a1
#> │ └─a2
#> └─B
#> ├─b1
#> │ └─b1a
#> └─b2
df <- hier_convert(h, as = "df")
hier_display(df)
#> Total
#> ├─A
#> │ ├─a1
#> │ └─a2
#> └─B
#> ├─b1
#> │ └─b1a
#> └─b2
h2 <- hier_import(df, from = "df")
hier_display(h2)
#> Total
#> ├─A
#> │ ├─a1
#> │ └─a2
#> └─B
#> ├─b1
#> │ └─b1a
#> └─b2
# check order
df <- data.frame(
level = c("@", "@@", "@@"),
name = c("T", "m", "f")
)
hier_display(hier_import(df, from = "df")) # automatically sorted (T, f, m)
#> T
#> ├─f
#> └─m
hier_display(hier_import(df, from = "df", keep_order = TRUE)) # original order (T, m, f)
#> T
#> ├─m
#> └─f