source("R/setup.R")$value
options(tibble.print_min = 5)
The class sc_data defines a common interface for open data datasets and responses from the /table
endpoint of the STATcube REST API.
It defines methods that are applicable to both datasources like acquiring metadata, labeling the data and aggregating results.
The sc_data class itself is not exported in r STATcubeR
.
Therefore, objects of the class should be created with one of the following functions
od_table()
obtains data from the OGD portal.
See the r ticle("od_table")
sc_table()
creates a request against the table endpoint of the STATcube REST API.
See the r ticle("sc_table")
sc_table_saved()
and sc_table_custom()
also use the /table
endpoint.
However, the request is specified via ids rather than a json file.To illustrate, we will use one of the OGD datasets to showcase the functionality of this class.
Notice however, that objects created with sc_table()
can be used interchangeably.
x <- od_table("OGD_krebs_ext_KREBS_1")
The data from the table can be extracted using the active binding $data
.
Notice how r tippy_dataset(x)
only includes codes and possibly some totals.
The data is always provided in a long format with one column for each field and one column for each measure.
x$data
It will be explained how labeled data can be obtained in the Tabulation section.
Metadata for a sc_data object includes labels and other information that is relevant to correctly parse the raw data.
The active binding $meta
contains at least the entries $source
, $measures
and $fields
.
The source field contains information about the data source.
The most important entries are code
and label
.
x$meta$source
On the bottom, we see that additional information about the source is available, namely label_en
, label_de
, etc.
These additional metadata entries might not be available for sc_table
objects.
This part of the metadata is a data.frame
with one row for each measure.
It contains codes and labels as well as the number of NAs found in $data
for that particular column.
x$meta$measures
The fields entry summarizes all classification fields i.e. categorical variables. It includes the codes and labels as well as the total code registered for the particular field.
x$meta$fields
To get more info about specific fields, use the $field()
method.
This will return all classification elements as a data.frame
.
x$field("Tumore")
x$field("Reporting year")
x$field("Province")
x$field("Sex")
The method $tabulate()
can be used to turn sc_table
objects into tidy data.frames.
See the r ticle("sc_tabulate")
for more defaults.
x$tabulate()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.