sc_table: Create a request against the /table endpoint

View source: R/table.R

sc_tableR Documentation

Create a request against the /table endpoint

Description

Send requests against the ⁠/table⁠ endpoint of the STATcube REST API. The requests can use three formats with corresponding functions

  • sc_table() uses a json file downloaded via the STATcube GUI

  • sc_table_custom() uses the ids of a database, measures and fields

  • sc_table_saved() uses a table uri of a saved table.

Those three functions all return an object of class "sc_table".

Usage

sc_table(json, language = NULL, add_totals = TRUE, key = NULL, json_file = NA)

sc_examples_list()

sc_example(filename)

sc_table_saved_list(key = NULL, server = "ext")

sc_table_saved(table_uri, language = NULL, key = NULL, server = "ext")

Arguments

json

Path to a json file, which was downloaded via the STATcube GUI ("Open Data API Request"). Alternatively, a json string which passes jsonlite::validate().

language

The language to be used for labeling. "en" (the default) will use english. "de" uses German. The third option "both" will import both languages by sending two requests to the ⁠/table⁠ endpoint.

add_totals

Should totals be added for each classification field in the json request?

key

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

json_file

Deprecated. Use json instead

filename

The name of an example json file.

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".

table_uri

Identifier of a saved table as returned by sc_table_saved_list()

Value

An object of class sc_table which contains the return value of the httr::POST() request in obj$response. The object also provides member functions to parse this response object. See sc_table_class for the class documentation.

Examples


my_table <- sc_table(json = sc_example("population_timeseries.json"))

# print
my_table

# get matadata for the table
my_table$meta

# get a data.frame
as.data.frame(my_table)

# get metadata for field 2
my_table$field(2)


# get the ids and labels of all saved tables
(saved_tables <- sc_table_saved_list())
table_uri <- saved_tables$id[1]

# get a table based on one of these ids
my_response <- sc_table_saved(table_uri)
as.data.frame(my_response)


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