The core function for downloading statistical data. Dimension filters
are passed as named arguments via ..., or via a prepared query object
from prepare_query().
Usage
get_data(
product,
measure,
...,
query = NULL,
lang = NULL,
simplify = TRUE,
cache = FALSE,
cache_location = NULL,
verbose = FALSE
)Arguments
- product
Character: product code (e.g.
"t10011"). Ignored whenqueryis provided.- measure
Character: measure name (e.g.
"itrfslut"). Ignored whenqueryis provided.- ...
Dimension filters as named arguments. Each name is a dimension name, each value is a character vector of filter values. Unspecified dimensions return all values. Ignored when
queryis provided.- query
A
<trafa_query>object fromprepare_query(). When provided,product,measure, and...are taken from the query object.- lang
Language code:
"SV"or"EN".- simplify
Add human-readable label columns alongside codes.
- cache
Logical. If
TRUEandcache_locationpoints at a SQLite file (or annxt_handlefrom nordstatExtras), the data is cached at cell granularity in that database. Supports concurrent multi-process read/write and cross-query cell reuse. RequiresnordstatExtras.- cache_location
Either a path to a
.sqlitefile or annxt_handlereturned bynordstatExtras::nxt_open(). Ignored unlesscache = TRUE.- verbose
Print request details.
Value
A tibble of data. Dimension columns use the dimension name;
when simplify = TRUE, additional {name}_label columns are added.
Measure values are in a column named after the measure.
Examples
# \donttest{
if (trafa_available()) {
# Direct fetch
get_data("t10011", "itrfslut", ar = "2024")
# With filters
get_data("t10011", "itrfslut",
ar = c("2023", "2024"),
drivm = c("102", "103"))
# From a prepared query
q <- prepare_query("t10011", "itrfslut", ar = "2024")
get_data(query = q)
}# }
#> # A tibble: 1 × 3
#> ar ar_label itrfslut
#> <chr> <chr> <dbl>
#> 1 2024 2024 14178