Code Monkey home page Code Monkey logo

bdsreader's People

Contributors

arjanhuizing avatar stefvanbuuren avatar

Stargazers

 avatar

Watchers

 avatar  avatar

bdsreader's Issues

format = 2.0 does not read d-score

Assume that jamesdemodata is installed.

library(bdsreader)

# 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
#> # 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 
#> # … with 48 more rows

# Read file with input data according to format "2.0".
data2 <- system.file("extdata/bds_v2.0/smocc/Laura_S.json", package = "jamesdemodata")
q <- read_bds(data2, format = "2.0")
q
#> # A tibble: 49 × 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 
#> # … with 39 more rows

table(t$yname)
#> 
#> bmi dsc hdc hgt wfh wgt 
#>  10   9   9  10  10  10
table(q$yname)
#> 
#> bmi hdc hgt wfh wgt 
#>  10   9  10  10  10

Created on 2021-10-17 by the reprex package (v2.0.1)

read_bds() does not work for JSON string, format 2.0

See problem https://github.com/growthcharts/jamesclient/issues?q=is%3Aissue+is%3Aclosed

library(bdsreader)
library(testthat)
fn2 <- system.file("extdata", "bds_v2.0", "smocc", "Laura_S.json", package = "jamesdemodata")
js2b <- jsonlite::toJSON(jsonlite::fromJSON(fn2), auto_unbox = TRUE)
test_that("Format 2.0 is read after toJSON(fromJSON(filename))", {
  expect_s3_class(read_bds(js2b), "tbl_df")
})
#> ── Warning (<text>:6:3): Format 2.0 is read after toJSON(fromJSON(filename)) ───
#> provided 3 variables to replace 1 variables
#> Backtrace:
#>   1. testthat::expect_s3_class(read_bds(js2b), "tbl_df")
#>   4. bdsreader::read_bds(js2b)
#>   9. bdsreader::verify(txt, auto_format, format, schema, ...)
.../bdsreader/R/read_bds.R:111:2
#>  10. bdsreader:::parse_valid(valid) 
.../bdsreader/bdsreader/R/verify.R:37:2
#>  12. base::`[<-.data.frame`(...) 
.../bdsreader/bdsreader/R/parse_valid.R:65:8
#> 
#> ── Error (<text>:6:3): Format 2.0 is read after toJSON(fromJSON(filename)) ─────
#> Error in `pp[pp$ElementNummer == 62L, "Waarde"]`: incorrect number of dimensions
#> Backtrace:
#>  1. testthat::expect_s3_class(read_bds(js2b), "tbl_df")
#>  9. bdsreader:::extract_dob(d, which = "01", v = v)
#> Error: Test failed

Created on 2021-11-25 by the reprex package (v2.0.1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.