Replace coded values in a brreg tibble with English (or Norwegian)
descriptions, following the eurostat package's label_eurostat()
pattern. Works on both data frames and character vectors.
Usage
brreg_label(x, dic = NULL, code = NULL, lang = c("en", "no"))Arguments
- x
A tibble from
brreg_entity(),brreg_search(),brreg_roles()orbrreg_regnskap(), or a character vector of codes.- dic
A character string naming the dictionary to use when
xis a character vector. One of"legal_form","nace","sector","role","role_group","regnskap_item","regnskap_group". Ignored whenxis a data frame (dictionaries are inferred from column names).- code
For data frames: character vector of column names for which to retain the original code alongside the label. A column with suffix
_codeis added before the label column. For example,brreg_label(x, code = "legal_form")addslegal_form_code.- lang
Language for labels:
"en"(default) or"no"(Norwegian, as published by BRREG and SSB).
Value
When x is a data frame: the same tibble with code columns
replaced by labels. When x is a character vector: a character
vector of labels, without names.
Which columns are labelled
legal_form (from legal_forms), role_code (from role_types),
role_group_code (from role_groups), nace_1, nace_2, nace_3
and sector_code (from the NACE and institutional-sector
dictionaries of get_brreg_dic()), and the accounts columns item
(from regnskap_items), group and statement (from
regnskap_groups), inside a nested items list-column as well as
on an unnested table. Other columns are never touched.
Codes with no dictionary entry pass through unchanged, and labels
are not codes, so applying brreg_label() twice is the same as
applying it once. Attributes of the input (such as
total_matches from brreg_search()) are preserved.
Network access
Legal-form and role dictionaries are bundled and never need the
network. NACE and sector dictionaries come from the SSB KLASS API on
first use in a session and are cached for the session; when KLASS
cannot be reached, or options(tidybrreg.offline = TRUE) is set, the
bundled English dictionaries are used instead and the result carries
their vintage. See get_brreg_dic() for the full policy.
See also
legal_forms, role_types, role_groups,
regnskap_items, regnskap_groups for bundled reference data,
get_brreg_dic() for fetching fresh dictionaries.
Other tidybrreg utilities:
brreg_validate(),
get_brreg_dic(),
tidybrreg_conditions,
tidybrreg_endpoints
Examples
if (FALSE) { # interactive() && curl::has_internet()
eq <- brreg_entity("923609016")
# Label all code columns
brreg_label(eq)
# Keep original codes alongside labels
brreg_label(eq, code = "legal_form")
# Label a character vector directly
brreg_label(c("AS", "ASA", "ENK"), dic = "legal_form")
brreg_label(c("AS", "ASA", "ENK"), dic = "legal_form", lang = "no")
brreg_label(c("total_assets", "net_income"), dic = "regnskap_item", lang = "no")
}