-
Notifications
You must be signed in to change notification settings - Fork 12
/
form_schema_ext.Rd
181 lines (145 loc) · 6.47 KB
/
form_schema_ext.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/form_schema_ext.R
\name{form_schema_ext}
\alias{form_schema_ext}
\title{Show the extended schema of one form.}
\usage{
form_schema_ext(
flatten = FALSE,
odata = FALSE,
parse = TRUE,
pid = get_default_pid(),
fid = get_default_fid(),
url = get_default_url(),
un = get_default_un(),
pw = get_default_pw(),
odkc_version = get_default_odkc_version(),
retries = get_retries(),
verbose = get_ru_verbose()
)
}
\arguments{
\item{flatten}{Whether to flatten the resulting list of lists (\code{TRUE})
or not (\code{FALSE}, default). Only applies to ODK Central version < 0.8.}
\item{odata}{Whether to sanitise the field names to match the way they will
be outputted for OData. While the original field names as given in the
XForms definition may be used as-is for CSV output, OData has some
restrictions related to the domain-qualified identifier syntax it uses.
Only applies to ODK Central version < 0.8.
Default: \code{FALSE}.}
\item{parse}{Whether to parse the form schema into a tibble of form field
type and name. This uses \code{\link{form_schema_parse}} internally.
If used together with \code{flatten=TRUE}, \code{\link{form_schema}} will raise
a warning and return the unparsed, flattened form schema.
Only applies to ODK Central version < 0.8.
Default: TRUE.}
\item{pid}{The numeric ID of the project, e.g.: 2.
Default: \code{\link{get_default_pid}}.
Set default \code{pid} through \code{ru_setup(pid="...")}.
See \code{vignette("Setup", package = "ruODK")}.}
\item{fid}{The alphanumeric form ID, e.g. "build_Spotlighting-0-8_1559885147".
Default: \code{\link{get_default_fid}}.
Set default \code{fid} through \code{ru_setup(fid="...")}.
See \code{vignette("Setup", package = "ruODK")}.}
\item{url}{The ODK Central base URL without trailing slash.
Default: \code{\link{get_default_url}}.
Set default \code{url} through \code{ru_setup(url="...")}.
See \code{vignette("Setup", package = "ruODK")}.}
\item{un}{The ODK Central username (an email address).
Default: \code{\link{get_default_un}}.
Set default \code{un} through \code{ru_setup(un="...")}.
See \code{vignette("Setup", package = "ruODK")}.}
\item{pw}{The ODK Central password.
Default: \code{\link{get_default_pw}}.
Set default \code{pw} through \code{ru_setup(pw="...")}.
See \code{vignette("Setup", package = "ruODK")}.}
\item{odkc_version}{The ODK Central version as a semantic version string
(year.minor.patch), e.g. "2023.5.1". The version is shown on ODK Central's
version page \verb{/version.txt}. Discard the "v".
\code{ruODK} uses this parameter to adjust for breaking changes in ODK Central.
Default: \code{\link{get_default_odkc_version}} or "2023.5.1" if unset.
Set default \code{get_default_odkc_version} through
\code{ru_setup(odkc_version="2023.5.1")}.
See \code{vignette("Setup", package = "ruODK")}.}
\item{retries}{The number of attempts to retrieve a web resource.
This parameter is given to \code{\link[httr]{RETRY}(times = retries)}.
Default: 3.}
\item{verbose}{Whether to display debug messages or not.
Read \code{vignette("setup", package = "ruODK")} to learn how \code{ruODK}'s
verbosity can be set globally or per function.}
}
\value{
A tibble containing the form definition.
For ODK Central 0.8, and with default parameters
(\code{parse=TRUE}) for ODK Central 0.7, \code{\link{form_schema}} returns
a tibble with the columns:
\itemize{
\item \code{name} The field name as given in the form schema.
\item \code{type} The field type, e.g. "string", "select1", etc.
\item \code{path} The XForms path of the field,
\item \code{ruodk_name} The predicted field name as generated by
\code{\link{odata_submission_get}}, prefixed by the path, additionally
cleaned with \code{\link[janitor]{make_clean_names}} to match the
cleaned column names from \code{\link{odata_submission_rectangle}}.
\item \code{label} The field label as given in the form schema.
If specific languages are available,
this column will return the \code{default} language or it will be empty
if this is not specified.
\item \code{label_lang} The field label in languange \emph{_lang} as
given in the form schema.
\item \code{choices} A list of lists containing at least \code{values} and,
if available, \code{labels} of the choices as given in the form schema.
If specific languages are available, this column will return the
\code{default} language or it will be empty if this is not specified.
Please notice that whenever choice filters are applied, this will return
the unfiltered choice list.
\item \code{choices_lang} A list of lists containing at least
\code{values} and, if available, \code{labels} of the choices in language
\emph{_lang} as given in the form schema.
Please notice that whenever choice filters are applied, this will return
the unfiltered choice list.
}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
}
\details{
ODK Central has introduced a new API endpoint in version 0.8 which
returns a parsed and flattened list of fields. This replaces the nested
form schema which is challenging to parse. This list is returned
by \code{\link{form_schema}}.
However this still misses important elements, in particular \code{labels} and
\code{choice_lists}.
\code{\link{form_schema_ext}} returns the same object as
\code{\link{form_schema}}
adding \code{labels} and \code{choice lists} in all languages available.
This is done by using the return object from \code{\link{form_xml}}.
It has the exact function signature as \code{\link{form_schema}}.
In that sense, any call to \code{\link{form_schema}} can be replaced
by \code{\link{form_schema_ext}}
This function, however, has been prepared with ODK Central version 0.8 or
higher. If you use it with an earlier version, a warning will be given.
}
\examples{
\dontrun{
# See vignette("setup") for setup and authentication options
# ruODK::ru_setup(svc = "....svc", un = "me@email.com", pw = "...")
# With current ODK Central (>0.7)
# get extended schema:
fsx <- form_schema_ext()
# print choice list in english:
fsx[fsx$name == "test_yn", "choices_english_(en)"][[1]]
# view the extended schema:
fsx
}
}
\seealso{
\url{https://docs.getodk.org/central-api-form-management/#getting-form-schema-fields}
\url{https://docs.getodk.org/central-api-form-management/#retrieving-form-xml}
Other form-management:
\code{\link{form_detail}()},
\code{\link{form_list}()},
\code{\link{form_schema}()},
\code{\link{form_xml}()}
}
\concept{form-management}