cso_get_data: Return a CSO table as a data frame

View source: R/cso_get_data.R

cso_get_dataR Documentation

Return a CSO table as a data frame

Description

Returns a CSO table from the CSO PxStat Application Programming Interface (API) as a data frame, with the option to give it in wide format (default) very wide or long format.

Usage

cso_get_data(
  table_code,
  wide_format = "wide",
  include_ids = FALSE,
  id_list = NULL,
  use_factors = TRUE,
  cache = TRUE,
  flush_cache = TRUE
)

Arguments

table_code

string. If the table_code is a filename or a path to a file, e.g. "QNQ22.json", it is imported from that file. Otherwise if it is only a table code e.g. "QNQ22", the file is downloaded from data.cso and checked to see if it is a valid table.

wide_format

string, one of "wide", "very_wide" or "tall". If "wide" (default) the table is returned in wide (human readable) format, with statistic as a column (if it exists). If "very_wide" the table is returned wide format and spreads the statistic column to rows. If "tall" the table is returned in tall (statistic and value) format.

include_ids

logical. The JSON-stat format stores variables as ids i.e. IE11 and labels i.e. Border. While the label is generally preferred, sometimes it is useful to have the ids to match on. If include_ids is TRUE (default) then ids are retrieved and appended to the table to the right of the original column with the name <columnName>.id.

id_list

either NULL (default) or a character vector of columns that should have ids appended if include_ids is TRUE. if NULL then every column that is not included in the vector remove_id will be used.

use_factors

logical. If TRUE (default) factors will be used in strings.

cache

logical. if TRUE (default) csodata will cache the result using R.cache. The raw data downloaded from the data.csi.ie is cached, which means that calling cso_get_data with the same table_code but different parameterswill result in cached data being used.

flush_cache

logical. If TRUE (default) the cache will be checked for old, unused files. Any files which have not been accessed in the last month will be deleted

Details

The data is pulled from the ResponseInstance service on the CSO API in JSON-Stat fromat, using the GET method from the httr package.

Value

data frame of the requested CSO table.

Examples

## Not run: 
tbl1 <- cso_get_data("QNQ22")
tbl2 <- cso_get_data("QLF07.json")

## End(Not run)

csodata documentation built on June 10, 2022, 5:09 p.m.