This function takes data from a json source, optionally validates the
contents against a JSON validation schema, perform checks, calculates
the D-score, calculates Z-scores and stores the data in an list with
elements psn
and xyz
.
read_bds(
txt = NULL,
auto_format = TRUE,
format = "1.0",
schema = NULL,
validate = FALSE,
append_ddi = FALSE,
intermediate = FALSE,
verbose = FALSE,
...
)
A JSON string, URL or file
Logical. Should the format be read from the data? Default
is TRUE
.
String. JSON data schema version number. There are currently
three schemas supported: "1.0"
, "1.1"
, "2.0"
and "3.0"
.
Formats "1.0"
and "1.1"
are included for backward compatibility only.
Use format = "3.0"
for new applications.
A file name (optionally including the path) with the JSON
validation schema.
The schema
argument overrides format
. The function extracts the
version number for the basename, and overwrites the
format
argument by version number.
Logical. Should the JSON-input be validated against the
JSON-schema? The default (FALSE
) bypasses checking. Set validate = TRUE
to obtain diagnostic information from the jsonvalidate::json_validate()
function.
Should the DDI responses be appended? (only used for JSON schema V1.0 and V2.0)
Logical. If TRUE
the function writes JSON files
with intermediate result to the working directory.
input.json
: the JSON input data;
bds.json
: a data frame with info per BDS;
ddi.json
: result of recoding BDS into GSED item names;
psn.json
: known fixed child covariates;
xy.json
: time-varying variables.
Show verbose output for centile::y2z()
Ignored
A list with elements named "psn"
and "xyz"
.
If txt
is unspecified or NULL
, then the return component will "xyz"
have zero rows.
The format
and schema
arguments specify the format of the JSON input
data argument txt
. The default format = "1.0"
expects that the JSON
input data conform to the schema specified in
system.file("schemas/bds_v1.0.json", package = "bdsreader")
. This is only
supported for legacy. We recommend format "3.0"
, which expects data
coded according to
system.file("schemas/bds_v3.0.json", package = "bdsreader")
.
The format can be specified in the JSON data file with an entry
named Format
. For auto_format == TRUE
, the data specification overrides
any format
and schema
arguments to the read_bds()
function.
Schema bds_v3.0.json
requires the Format
field, so the correct format
is automatically set by the data.
Legacy note: If you erroneously read a JSON file of format "1.0"
using
format "2.0"
you may see an error:
Error ...: incorrect number of dimensions
.
In that make sure that you are reading with the format = "1.0"
argument.
Reversely, if you erroneously read a JSON file of format "2.0"
using format
"1.0"
you may see messages .ClientGegevens should be object
and
Missing 'ClientGegevens$Groepen'
. In that case, specify format = "2.0"
.
fn <- system.file("json", "examples", "maria1.json", package = "jamesdemodata")
m <- read_bds(fn)
m
#> <bdsreader>
#> $persondata:
#> # A tibble: 1 × 12
#> id name src dnr sex gad ga smo bw hgtm hgtf agem
#> <int> <chr> <chr> <chr> <chr> <dbl> <dbl> <int> <dbl> <dbl> <dbl> <dbl>
#> 1 -1 fa308134-06… 1234 NA fema… 189 27 0 990 167 190 27
#>
#> $timedata:
#> # A tibble: 11 × 8
#> age xname yname zname zref x y z
#> <dbl> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 0.0849 age hgt hgt_z nl_2012_hgt_female_27 0.0849 38 -0.158
#> 2 0.167 age hgt hgt_z nl_2012_hgt_female_27 0.167 43.5 0.047
#> 3 0 age wgt wgt_z nl_2012_wgt_female_27 0 0.99 0.19
#> 4 0.0849 age wgt wgt_z nl_2012_wgt_female_27 0.0849 1.25 -0.203
#> 5 0.167 age wgt wgt_z nl_2012_wgt_female_27 0.167 2.1 0.015
#> 6 0.0849 age hdc hdc_z nl_2012_hdc_female_27 0.0849 27 -0.709
#> 7 0.167 age hdc hdc_z nl_2012_hdc_female_27 0.167 30.5 -0.913
#> 8 0.0849 age bmi bmi_z nl_1997_bmi_female_nl 0.0849 8.66 -5.72
#> 9 0.167 age bmi bmi_z nl_1997_bmi_female_nl 0.167 11.1 -3.77
#> 10 0.0849 hgt wfh wfh_z nl_2012_wfh_female_ 38 1.25 -0.001
#> 11 0.167 hgt wfh wfh_z nl_2012_wfh_female_ 43.5 2.1 0.326
data2 <- system.file("extdata", "bds_v3.0", "smocc", "Laura_S.json",
package = "jamesdemodata")
q <- read_bds(data2)
q
#> <bdsreader>
#> $persondata:
#> # A tibble: 1 × 17
#> id name src dnr sex gad ga smo bw hgtm hgtf agem blbf
#> <int> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
#> 1 -1 Laura… 0 NA fema… 276 39 0 2950 164 179 NA NA
#> # ℹ 4 more variables: blbm <int>, eduf <int>, edum <int>, par <int>
#>
#> $timedata:
#> # A tibble: 58 × 8
#> age xname yname zname zref x y z
#> <dbl> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 0 age hgt hgt_z nl_1997_hgt_female_nl 0 48 -1.52
#> 2 0.101 age hgt hgt_z nl_1997_hgt_female_nl 0.101 53.5 -0.499
#> 3 0.159 age hgt hgt_z nl_1997_hgt_female_nl 0.159 56 -0.261
#> 4 0.236 age hgt hgt_z nl_1997_hgt_female_nl 0.236 59.5 0.163
#> 5 0.485 age hgt hgt_z nl_1997_hgt_female_nl 0.485 65.5 -0.259
#> 6 0.753 age hgt hgt_z nl_1997_hgt_female_nl 0.753 71.5 0.131
#> 7 1.02 age hgt hgt_z nl_1997_hgt_female_nl 1.02 75 -0.18
#> 8 1.25 age hgt hgt_z nl_1997_hgt_female_nl 1.25 80 0.421
#> 9 1.54 age hgt hgt_z nl_1997_hgt_female_nl 1.54 84 0.527
#> 10 2.04 age hgt hgt_z nl_1997_hgt_female_nl 2.04 90 0.67
#> # ℹ 48 more rows
# Equivalent, but specifying the built-in schema file bds_v3.0.json
schema3 <- system.file("schemas", "bds_v3.0.json", package = "bdsreader")
r <- read_bds(data2, schema = schema3)
identical(q, r)
#> [1] TRUE
# Automatic detection of format 3.0
# s <- read_bds(data2)
# identical(q, s)
# Reading data with older format (bds_v1.0)
data1 <- system.file("extdata", "bds_v1.0", "smocc", "Laura_S.json",
package = "jamesdemodata")
t <- read_bds(data1)
t
#> <bdsreader>
#> $persondata:
#> # A tibble: 1 × 12
#> id name src dnr sex gad ga smo bw hgtm hgtf agem
#> <int> <chr> <chr> <chr> <chr> <dbl> <dbl> <int> <dbl> <dbl> <dbl> <dbl>
#> 1 -1 Laura S 0 NA female 276 39 0 2950 164 179 27
#>
#> $timedata:
#> # A tibble: 58 × 8
#> age xname yname zname zref x y z
#> <dbl> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 0 age hgt hgt_z nl_1997_hgt_female_nl 0 48 -1.52
#> 2 0.101 age hgt hgt_z nl_1997_hgt_female_nl 0.101 53.5 -0.499
#> 3 0.159 age hgt hgt_z nl_1997_hgt_female_nl 0.159 56 -0.261
#> 4 0.236 age hgt hgt_z nl_1997_hgt_female_nl 0.236 59.5 0.163
#> 5 0.485 age hgt hgt_z nl_1997_hgt_female_nl 0.485 65.5 -0.259
#> 6 0.753 age hgt hgt_z nl_1997_hgt_female_nl 0.753 71.5 0.131
#> 7 1.02 age hgt hgt_z nl_1997_hgt_female_nl 1.02 75 -0.18
#> 8 1.25 age hgt hgt_z nl_1997_hgt_female_nl 1.25 80 0.421
#> 9 1.54 age hgt hgt_z nl_1997_hgt_female_nl 1.54 84 0.527
#> 10 2.04 age hgt hgt_z nl_1997_hgt_female_nl 2.04 90 0.67
#> # ℹ 48 more rows
# same, but using a built-in schema file
schema1 <- system.file("schemas", "bds_v1.0.json", package = "bdsreader")
u <- read_bds(data1, schema = schema1)
identical(t, u)
#> [1] TRUE