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.

Constructing sc_data objects

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

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

Data

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

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.

Source

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.

Measures

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

Fields

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

Field information

To get more info about specific fields, use the $field() method. This will return all classification elements as a data.frame.

{.tabset .tabset-pills .tabset-fade}

Tumor types

x$field("Tumore")

Year

x$field("Reporting year")

Province

x$field("Province")

Sex

x$field("Sex")

Tabulation

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()


statistikat/STATcubeR documentation built on Dec. 3, 2024, 8:04 p.m.