sc_data {STATcubeR} | R Documentation |
Common interface for STATcubeR datasets
Description
This class represents a common interface for datasets returned from the
STATcube REST API and OGD datasets. sc_data
objects are usually created with
od_table()
or sc_table()
.
Active bindings
data
the raw data. A data.frame that uses codes for all field variables and for all column names. To obtain labeled data, use
$tabulate()
.language
language to be used for labeling.
"en"
or"de"
meta
A list containing metadata about the dataset. It has at least the following entries
-
$source
is a dataframe with a single row that contains information on the data source. -
$measures
is a dataframe with one row for every measure in the dataset. It contains codes and labels for each measure as well as the number ofNAs
. Derived classes might add additional columns. -
$fields
is a dataframe with one row for every field in the dataset. It contains codes and labels for each measure as well as the total codes. Derived classes might add additional columns
-
recode
An object of class sc_recoder that can be used to change labels and perform other recoding operations.
Methods
Public methods
Method new()
This class is not exported. Use od_table()
or sc_table()
to initialize objects of class sc_data
.
Usage
sc_data$new(data, meta, fields)
Arguments
data, meta, fields
raw data, metadata and field information. Do not use directly but initialize objects with
sc_table()
orod_table()
Method field()
get information about a specific field. The format of
the return value is similar to $meta
. A data.frame
that includes
codes and labels for each level of the field.
Usage
sc_data$field(i = 1)
Arguments
i
specifier for the field. Integer or character. If an integer is provided, it should match the row number in
$meta$fields
. If a character is provided, the field is matched usingpmatch()
on all available codes and labels.
Examples
x <- od_table("OGD_krebs_ext_KREBS_1") x$field(1) x$field("Sex")
Method tabulate()
create a tidy dataset. See sc_tabulate()
for details.
Usage
sc_data$tabulate(...)
Arguments
...
arguments that are passed down to
sc_tabulate()
Examples
x <- od_table("OGD_krebs_ext_KREBS_1") x$tabulate("Reporting year", "Sex")
Method total_codes()
Usage
sc_data$total_codes(...)
Arguments
...
key value pairs to define the total codes. Key should be a field code and value a code from
$field(i)
. If empty, it will return a data.frame with all specified total codes. Keys and values can also use labels instead of codes. See examples.
Examples
earnings <- od_table("OGD_veste309_Veste309_1") earnings$total_codes(Sex = "Sum total", Citizenship = "Total", Region = "Total", `Form of employment` = "Total") earnings$tabulate("Form of employment") earnings$tabulate("Sex", "Form of employment")
Method clone()
The objects of this class are cloneable with this method.
Usage
sc_data$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
## create a new sc_data object via od_table()
x <- od_table("OGD_krebs_ext_KREBS_1")
## show data
x$data
## show metadata
x$meta
## ------------------------------------------------
## Method `sc_data$field`
## ------------------------------------------------
x <- od_table("OGD_krebs_ext_KREBS_1")
x$field(1)
x$field("Sex")
## ------------------------------------------------
## Method `sc_data$tabulate`
## ------------------------------------------------
x <- od_table("OGD_krebs_ext_KREBS_1")
x$tabulate("Reporting year", "Sex")
## ------------------------------------------------
## Method `sc_data$total_codes`
## ------------------------------------------------
earnings <- od_table("OGD_veste309_Veste309_1")
earnings$total_codes(Sex = "Sum total", Citizenship = "Total",
Region = "Total", `Form of employment` = "Total")
earnings$tabulate("Form of employment")
earnings$tabulate("Sex", "Form of employment")