scb_list: List directory structure or table metadata

Description Usage Arguments Details Value Examples

Description

By default, will return a list of all highest-level directories, in English, in the ssd database. If an ID path is provided, either all subdirectories to the specified path will be shown, or, if the ID path refers to a table, the table metadata.

Usage

1
2
scb_list(lang = "en", database_id = "ssd", id = NULL,
  unnest_variables = TRUE, call_tracker = NULL)

Arguments

lang

"en" for English, "sv" for Swedish

database_id

Database to search

id

Path to search in database

unnest_variables

TRUE will unnest the variable data to be easier to read

call_tracker

Used in internal package functions

Details

The database_id argument should normally not be touched; "ssd" is the main database for national statistics and, as of March 2019, the only one accessible via the API and this package. To see if any other databases are available, one can set the database_id argument to "": i.e., call scb_list(database_id = ""). The ID is provided as a path, e.g. "AM/AM0101/AM0101A", where each element of the path refers to either a directory, a subdirectory, or a table ID. The IDs can most easily be determined by either sequentially interrogating the database (starting with no ID argument), or by looking through the cached data in scb_cache.

The function uses the httr package to submit the API request, and jsonlite to parse the response, which it then returns. If the ID path refers to a specific table, the returned data will contain all metadata available for that table, rather than a directory list; this metadata will be unnested using unnest to make it more readable.

If the GET call returns with status code 429 (too many requests), the function will wait until the last call to the API has cleared, then try again. This normally resolves within, at most, 10 seconds, but there is also a fixed limit of 50,000 attempts until the function exits to prevent infinite loops.

Value

A 2-element list, where the first element is the status_code from GET, and the second is a data.frame containing the parsed respon, or an empty data.frame if the status_code is not 200

Examples

1
2
3
4
5
6
## Not run: 
scb_list()
scb_list(id = "AM/AM0101/AM0101A")
scb_list(lang = "sv", id = "LE")

## End(Not run)

olhmr/rscb documentation built on May 15, 2019, 10:40 p.m.