sc_schema: Create a request against the /schema endpoint

View source: R/schema.R

sc_schemaR Documentation

Create a request against the /schema endpoint

Description

Invoke the /schema endpoint of the STATcube REST API. This endpoint can be used to get all available databases and tables as well as metadata about specific databases.

The main function sc_schema() can be used with any resource id. sc_schema_catalogue() and sc_schema_db() are very simple wrapper functions around sc_schema() and are comparable to the catalogue explorer or the table view of the STATcube GUI.

The responses of the API are tree-like data structures which are wrapped into a class called sc_schema to simplify the usage in R.

Usage

sc_schema(id = NULL, depth = NULL, language = NULL, key = NULL, server = "ext")

## S3 method for class 'sc_schema'
print(x, tree = NULL, ..., limit = 30)

sc_schema_flatten(x, type)

sc_schema_catalogue(depth = "folder", ...)

sc_schema_db(id, depth = "valueset", language = c("en", "de"), key = NULL)

Arguments

id

A resource identifier in uid format. In case of sc_schema_db(), this should be a database id. For sc_schema() any resource-id (folder, measure, table, ...) is accepted.

depth

If provided, the request will recurse into the given level. For datasets, available options are NULL (no recursion), "folder", "field" and "valueset". For the catalogue, only NULL and "folder" are applicable.

language

The language to be used for labeling. "en" or "de"

key

(string) An API key. To display your key, call sc_browse_preferences().

server

A STATcube API server. Defaults to the external Server via "ext". Other options are "red" for the editing server and "prod" for the production server. External users should always use the default option "ext".

x

an object of class sc_schema() i.e. the return value of sc_schema(), sc_schema_db() or sc_schema_catalogue().

tree

whether to use the data.tree package for printing.

limit, ...

passed to data.tree::print.Node() if tree is set to TRUE. Ignored otherwise.

type

a schema type such as "DATABASE", "VALUE" or "TABLE". See the API reference for a list of all schema types.

Value

  • for sc_schema() and sc_schema_db(): an object of class sc_schema

  • for sc_schema_flatten(): a data.frame

  • for sc_schema_catalogue(): a list

Functions

  • sc_schema_flatten(): turns a sc_schema object into a data.frame

  • sc_schema_catalogue(): is similar to the catalogue explorer of the STATcube GUI and returns a tree-type object containing all databases and tables.

  • sc_schema_db(): is similar to the table view of the STATcube GUI and gives information about all measures and classification fields for a specific database

Printing with data.tree

limit and ... will simply be ignored if tree is set to FALSE, which is the default. The printing via data.tree can take longer than the default implementation because x will need to be converted into a data.tree node. To use data.tree printing permanently, use

options(STATcubeR.print_tree = TRUE)

Examples


my_catalogue <- sc_schema_catalogue()

## print
my_catalogue

## access the parsed catalogue
my_catalogue$Statistics$`Labour Market`
my_catalogue$Statistics$`Labour Market`$`Working hours (Labour Force Survey)`

db_schema <- sc_schema_db("deake005")

# printing
db_schema

# access child nodes
db_schema$`Demographic Characteristics`
db_schema$`Demographic Characteristics`$Gender$Gender
db_schema$`Demographic Characteristics`$Gender$Gender$male

# access the raw response from httr::GET()
my_response <- attr(db_schema, "response")
my_response$headers$date
my_content <- httr::content(my_response)
my_content$label

# print with data.tree

 treeX_B1 <- sc_schema("str:group:deake005:X_B1", depth = "valueset")
 print(treeX_B1, tree = TRUE)


STATcubeR documentation built on April 3, 2025, 7:31 p.m.