
Dictionary-encode a table's set columns, or undo it
Source:R/dictionary.R
en_characters_to_factors.Rden_characters_to_factors() converts every column named by a declared set
to a factor whose levels are that set; en_factors_to_characters() converts
factor columns back to character. The pair is what the storage layer uses at
the file boundary (see the storage_dictionary option), and it is exported
because a caller reading a store directly – rather than through
getData() or obj2mem() – has to do the same.
Usage
en_characters_to_factors(x, scenario, verbose = isVerbose())
en_factors_to_characters(x, scenario = NULL)Details
Only a column whose NAME is a set of the problem is encoded, and only when
it is character, so a numeric set such as year is left alone. The levels
are the declared set rather than the column's distinct values, so the codes
mean the same thing in every table and a join between two tables compares
integer codes instead of reconciling two level sets. A value outside the
declared set would become NA, so it is kept as a level instead and
reported once.
Examples
if (FALSE) { # \dontrun{
d <- getData(scen, "pDemand", merge = TRUE)
f <- en_characters_to_factors(d, scen) # region, timeslice as dictionaries
en_factors_to_characters(f) # back again
} # }