Returns a data frame containing rows from a published dataset. Filters and display options are submitted to the API as a stored query; the same inputs always produce the same query ID so repeated calls are efficient.
Usage
statswales_get_dataset(
dataset_id,
lang = "en-gb",
page_number = 1,
page_size = 10000,
filter = NULL,
options = list(use_raw_column_names = FALSE, use_reference_values = FALSE,
data_value_type = "formatted"),
sort_by = NULL,
all_pages = TRUE,
tidy = TRUE
)Arguments
- dataset_id
A dataset UUID string. Use
statswales_list_datasets()to find dataset IDs.- lang
Language for text values. One of
"en-gb"(default),"en","cy-gb", or"cy".- page_number
Page of results to return. Default
1. Only used whenall_pages = FALSE.- page_size
Rows per page. Default
10000(the API maximum).- filter
A list of filter objects. Each element is a named list mapping a column name (from
statswales_get_filters()) to a character vector of reference codes. Multiple list elements use AND logic; multiple codes within one element use OR logic. Example:list(list(Year = c("2020", "2021")), list(Area = c("W92000004"))).- options
A named list of display options:
use_raw_column_namesFALSE(default) returns human-readable column names;TRUEreturns internal fact-table names.use_reference_valuesFALSE(default) returns human-readable values;TRUEreturns reference codes.data_value_typeOne of
"raw","raw_extended","formatted"(default),"formatted_extended", or"with_note_codes".
Note: as of July 2026 the StatsWales API ignores
use_raw_column_namesanduse_reference_values, so output always uses human-readable column names and values regardless of these settings. Onlydata_value_typecurrently changes the output.- sort_by
Optional sort order. Either a ready-made string in the API's
"column:direction"format (e.g."Year:desc"), or a named character vector such asc(Year = "desc", Area = "asc"). Directions are"asc"or"desc".- all_pages
If
TRUE(default), automatically fetches and row-binds all pages so the entire dataset is returned. Set toFALSEto retrieve a single page controlled bypage_numberandpage_size.- tidy
If
TRUE(default), the result is cleaned for analysis: the API's internal*_sortcolumns are dropped, whitespace padding is stripped, and numeric-looking columns (such as the data values) are converted to numeric. Set toFALSEto return the API response as-is.
Examples
if (FALSE) { # \dontrun{
datasets <- statswales_list_datasets()
id <- datasets$id[1]
# Entire dataset, human-readable (default)
df <- statswales_get_dataset(id)
# A single page of 100 rows
df_page <- statswales_get_dataset(id, all_pages = FALSE, page_size = 100)
# Filtered to specific years
filters <- statswales_get_filters(id)
df_filtered <- statswales_get_dataset(
id,
filter = list(list(Year = c("2020", "2021")))
)
} # }