sc_table_custom {STATcubeR} | R Documentation |
Create custom tables
Description
Define requests against the /table endpoint by providing
URIs to databases, measures and fields.
The URIs can be obtained using sc_schema_db()
.
See the Custom tables article
for more details.
Usage
sc_table_custom(
db,
measures = c(),
dimensions = c(),
language = c("en", "de"),
add_totals = TRUE,
key = NULL,
recodes = NULL,
dry_run = FALSE
)
sc_recode(field, map = NULL, total = FALSE)
Arguments
db |
The uid of a database. Must be of type |
measures |
A character vector of uids for measures. Each entry must be
of type |
dimensions |
A character vector of dimensions for the cube. Can be
either of type |
language |
The language to be used for labeling. "en" (the default) will use English. "de" uses German. |
add_totals |
Should totals be added for each classification field in
the json request? Ignored if |
key |
( |
recodes |
One or more recodes that were generated via |
dry_run |
If |
field |
An uid of a classification field to be recoded. The provided
uid should also be passed in the |
map |
A list of ids for values (type |
total |
Add totals to the field? If |
Value
for
sc_table_custom()
: an object of classsc_table
for
sc_recode()
: alist
that is a suitable input for parameter"recode"
insc_table_custom()
Functions
-
sc_recode()
: creates a recode object which can be used for therecode
parameter ofsc_table_custom()
Schema objects in parameters
it is possible to pass sc_schema
objects (usually generated by
sc_schema_db()
) instead of ids in sc_table_custom()
and sc_recode()
.
If provided, the schema objects will be converted into ids via $id
.
Error handling
Unfortunately, the API gives fairly vague error messages in case a
custom table request is ill defined. For this reason, sc_table_custom()
applies some simple heuristics and throws warnings if inconsistencies
in the provided parameters are recognized. The following conditions are
currently checked
the parameter
db
is of typeDATABASE
all entries in
measures
are of typeMEASURE
,COUNT
orSTATFN
all entries in
dimensions
are of typeVALUESET
orFIELD
all entries in
field
are of typeVALUESET
orFIELD
all entries in
map
are of typeVALUE
all fields in
recodes
are also present indimensions
the first two arguments of
sc_recode()
are consistent, i.e. if the providedVALUE
s belong to theVALUESET/FIELD
Examples
sc_table_custom("str:database:detouextregsai")
sc_table_custom(
"str:database:detouextregsai",
dimensions = "str:field:detouextregsai:F-DATA1:C-SDB_TIT-0"
)
sc_table_custom(
db = "str:database:detouextregsai",
measures = c(
"str:statfn:detouextregsai:F-DATA1:F-ANK:SUM",
"str:measure:detouextregsai:F-DATA1:F-UEB"
),
dimensions = c(
"str:field:detouextregsai:F-DATA1:C-SDB_TIT-0",
"str:valueset:detouextregsai:F-DATA1:C-C93-2:C-C93SUM-0"
)
)
schema <- sc_schema_db("detouextregsai")
region <- schema$`Other Classifications`$`Tourism commune [ABO]`$
`Regionale Gliederung (Ebene +1)`
month <- schema$`Mandatory fields`$`Season/Tourism Month`
x <- sc_table_custom(
schema,
schema$Facts$Arrivals,
list(month, region),
recodes = c(
sc_recode(region, total = FALSE, map = list(
region$Achensee,
list(region$Arlberg, region$`Ausseerland-Salzkammergut`)
)),
sc_recode(month, total = FALSE)
)
)
x$tabulate()