-
Notifications
You must be signed in to change notification settings - Fork 1
/
sc_table_custom.Rd
111 lines (94 loc) · 3.55 KB
/
sc_table_custom.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/table_custom.R
\name{sc_table_custom}
\alias{sc_table_custom}
\alias{sc_recode}
\title{Create custom tables}
\usage{
sc_table_custom(
db,
measures = c(),
dimensions = c(),
language = c("en", "de"),
add_totals = TRUE,
key = NULL,
recodes = NULL
)
sc_recode(field, map = NULL, total = FALSE)
}
\arguments{
\item{db}{The uid of a database. Must be of type \code{DATASET}}
\item{measures}{A character vector of uids for measures. Each entry must be
of type \code{MEASURE}, \code{STAT_FUNCTION} or \code{COUNT}.}
\item{dimensions}{A character vector of dimensions for the cube. Can be
either of type \code{FIELD} or type \code{VALUESET}. Those entries are referred to
as \code{fields} in the parsed API response}
\item{language}{The language to be used for labeling. "en"
(the default) will use english. "de" uses german.}
\item{add_totals}{Should totals be added for each classification field in
the json request? Ignored if \code{recodes} is used.}
\item{key}{(\code{string}) An API key. To display your key, call
\code{\link[=sc_browse_preferences]{sc_browse_preferences()}}.}
\item{recodes}{One or more recodes that were generated via \code{\link[=sc_recode]{sc_recode()}}.
If more than one recode is supplied, recodes should be concatinated with
\code{\link[=c]{c()}}.}
\item{field}{An uid of a classification field to be recoded. The provided
uid should also be passed in the \code{dimensions} parameter of
\code{\link[=sc_table_custom]{sc_table_custom()}}.}
\item{map}{A list of ids for values (type \code{VALUE}) This can also be a nested
list if items should be grouped. See examples}
\item{total}{Add totals to the field? If \code{map} is provided, the totals
will correspond to the filtered data.}
}
\description{
Define requests against the /table endpoint by providing
URIs to databases, measures and fields.
The URIs can be obtained using \code{\link[=sc_schema_db]{sc_schema_db()}}.
See the \href{https://statistikat.github.io/STATcubeR/articles/sc_table_custom.html}{Custom tables article}
for more details.
}
\section{Functions}{
\itemize{
\item \code{sc_recode()}: creates a recode object which can be used
for the \code{recode} parameter of \code{\link[=sc_table_custom]{sc_table_custom()}}
}}
\section{Schema objects in parameters}{
it is possible to pass \code{sc_schema} objects (usually generated by
\code{\link[=sc_schema_db]{sc_schema_db()}}) instead of ids in \code{\link[=sc_table_custom]{sc_table_custom()}} and \code{\link[=sc_recode]{sc_recode()}}.
If provided, the schema objects will be converted into ids via \verb{$id}.
}
\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()
}