From 2a83e84379bbbde9b7d252daddd1acbf6c8bd9ff Mon Sep 17 00:00:00 2001 From: "mike.stackhouse" Date: Mon, 3 Jun 2024 18:31:11 +0000 Subject: [PATCH 01/11] this was amazingly a 1 line flip to get parity in existing tests. --- R/read_dataset_json.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/read_dataset_json.R b/R/read_dataset_json.R index 161b382..883d846 100644 --- a/R/read_dataset_json.R +++ b/R/read_dataset_json.R @@ -35,7 +35,12 @@ read_dataset_json <- function(file) { } # Read the file and convert to datasetjson object - ds_json <- jsonlite::fromJSON(file_contents) + ds_json <- yyjsonr::read_json_str( + paste0(file_contents, collapse=""), + yyjsonr::opts_read_json( + promote_num_to_string = TRUE + ) + ) # Pull the object out with a lot of assumptions because the format has already # been validated From bc68a47b50fabd152a6e747a6d60b0cd94bf8659 Mon Sep 17 00:00:00 2001 From: "mike.stackhouse" Date: Mon, 3 Jun 2024 19:22:44 +0000 Subject: [PATCH 02/11] For the row vectors to write out per standard, they have to be unnamed --- R/dataset_metadata.R | 2 +- tests/testthat/test-datasetjson.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/dataset_metadata.R b/R/dataset_metadata.R index 22edcb1..e65560e 100644 --- a/R/dataset_metadata.R +++ b/R/dataset_metadata.R @@ -95,7 +95,7 @@ set_item_data <- function(x, .data, ...) { # Insert into object in proper spots x[[1]][['records']] <- records - x[[1]][['itemData']] <- item_data + x[[1]][['itemData']] <- unname(item_data) x } diff --git a/tests/testthat/test-datasetjson.R b/tests/testthat/test-datasetjson.R index 131ff46..52576a0 100644 --- a/tests/testthat/test-datasetjson.R +++ b/tests/testthat/test-datasetjson.R @@ -49,10 +49,10 @@ test_that("datasetjson object builds with minimal defaults", { expect_equal(ds_json$clinicalData$itemGroupData$IG.IRIS$items, iris_items_list) # Verify that data are attached properly with ITEMGRPUPSEQ attached - iris_test <- cbind( + iris_test <- unname(cbind( ITEMGROUPDATASEQ = 1:nrow(iris), iris - ) + )) expect_equal(ds_json$clinicalData$itemGroupData$IG.IRIS$itemData, iris_test) }) From aeeab5b497723bce65c570cf936a584e5b5b48c2 Mon Sep 17 00:00:00 2001 From: "mike.stackhouse" Date: Mon, 3 Jun 2024 19:23:19 +0000 Subject: [PATCH 03/11] Flip writer to yyjsonr --- R/write_dataset_json.R | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/R/write_dataset_json.R b/R/write_dataset_json.R index af7c165..099bba0 100644 --- a/R/write_dataset_json.R +++ b/R/write_dataset_json.R @@ -32,18 +32,23 @@ write_dataset_json <- function(x, file, pretty=FALSE) { } # Create the JSON text - js <- jsonlite::toJSON( - x, - dataframe = "values", - na = "null", + json_opts <- yyjsonr::opts_write_json( + pretty = pretty, auto_unbox = TRUE, - pretty = pretty) + ) if (!missing(file)) { # Write file to disk - cat(js, "\n", file = file) + yyjsonr::write_json_file( + x, + filename = file, + opts = json_opts + ) } else { # Print to console - js + yyjsonr::write_json_str( + x, + opts = json_opts + ) } } From d31433c6429bf996af440e37d88539481c92e37a Mon Sep 17 00:00:00 2001 From: "mike.stackhouse" Date: Mon, 3 Jun 2024 19:31:17 +0000 Subject: [PATCH 04/11] Allow file to go directly to yyjsonr reader --- R/read_dataset_json.R | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/R/read_dataset_json.R b/R/read_dataset_json.R index 883d846..a533559 100644 --- a/R/read_dataset_json.R +++ b/R/read_dataset_json.R @@ -23,24 +23,33 @@ #' dat <- read_dataset_json(js) read_dataset_json <- function(file) { + json_opts <- yyjsonr::opts_read_json( + promote_num_to_string = TRUE + ) + if (path_is_url(file)) { # Url? file_contents <- read_from_url(file) + ds_json <- yyjsonr::read_json_str( + file_contents, + opts = json_opts + ) } else if (file.exists(file)) { # File on disk? - file_contents <- readLines(file) + ds_json <- yyjsonr::read_json_file( + file, + opts = json_opts + ) } else { # Direct file contents? - file_contents <- file + ds_json <- yyjsonr::read_json_str( + file, + opts = json_opts + ) } # Read the file and convert to datasetjson object - ds_json <- yyjsonr::read_json_str( - paste0(file_contents, collapse=""), - yyjsonr::opts_read_json( - promote_num_to_string = TRUE - ) - ) + # Pull the object out with a lot of assumptions because the format has already # been validated From 35ac486a574f9e09dd328601a36c123cbadae8c6 Mon Sep 17 00:00:00 2001 From: "mike.stackhouse" Date: Mon, 3 Jun 2024 19:32:44 +0000 Subject: [PATCH 05/11] docs and deps --- DESCRIPTION | 7 ++++--- NAMESPACE | 8 ++++++-- R/zzz.R | 2 +- man/read_dataset_json.Rd | 1 + 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f30c31d..ffe877f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,13 +21,14 @@ Language: en-US License: Apache License (>= 2) LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 -Depends: R (>= 3.5) +RoxygenNote: 7.3.1 +Depends: R (>= 4.2) Imports: - jsonlite (>= 1.8.0), + yyjsonr (0.1.18), jsonvalidate (>= 1.3.1) Suggests: testthat (>= 2.1.0), + jsonlite (>= 1.8.0) knitr, haven, rmarkdown, diff --git a/NAMESPACE b/NAMESPACE index c882af0..a9a5cd9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,8 +23,12 @@ export(set_source_system) export(set_study_oid) export(validate_dataset_json) export(write_dataset_json) -importFrom(jsonlite,fromJSON) -importFrom(jsonlite,toJSON) importFrom(jsonvalidate,json_validate) importFrom(tools,file_path_sans_ext) importFrom(utils,tail) +importFrom(yyjsonr,opts_read_json) +importFrom(yyjsonr,opts_write_json) +importFrom(yyjsonr,read_json_file) +importFrom(yyjsonr,read_json_str) +importFrom(yyjsonr,write_json_file) +importFrom(yyjsonr,write_json_str) diff --git a/R/zzz.R b/R/zzz.R index bba701f..9e26d2b 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,5 +1,5 @@ #' @importFrom jsonvalidate json_validate -#' @importFrom jsonlite fromJSON toJSON +#' @importFrom yyjsonr opts_write_json opts_read_json write_json_file write_json_str read_json_str read_json_file #' @importFrom tools file_path_sans_ext #' @importFrom utils tail NULL diff --git a/man/read_dataset_json.Rd b/man/read_dataset_json.Rd index b5ce954..811cc6f 100644 --- a/man/read_dataset_json.Rd +++ b/man/read_dataset_json.Rd @@ -21,6 +21,7 @@ either a file path on disk of a URL which contains the Dataset JSON file. # Read from disk \dontrun{ dat <- read_dataset_json("path/to/file.json") + # Read file from URL dat <- dataset_json('https://www.somesite.com/file.json') } From 6ebd048aa8b80833f76f4a0224c00756dcf0590a Mon Sep 17 00:00:00 2001 From: "mike.stackhouse" Date: Mon, 3 Jun 2024 19:43:26 +0000 Subject: [PATCH 06/11] Increment yyjsonr version for CI/CD failures --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ffe877f..ffca9df 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,7 +24,7 @@ Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 Depends: R (>= 4.2) Imports: - yyjsonr (0.1.18), + yyjsonr (0.1.20), jsonvalidate (>= 1.3.1) Suggests: testthat (>= 2.1.0), From b12bdd575f2c7277ce65c4ea7485fbb4519695d9 Mon Sep 17 00:00:00 2001 From: "mike.stackhouse" Date: Mon, 3 Jun 2024 19:44:37 +0000 Subject: [PATCH 07/11] whoops --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ffca9df..c1e09be 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,7 +24,7 @@ Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 Depends: R (>= 4.2) Imports: - yyjsonr (0.1.20), + yyjsonr (>= 0.1.18), jsonvalidate (>= 1.3.1) Suggests: testthat (>= 2.1.0), From 8306fd6cad7cb1e733850902d46bf9e973dff08a Mon Sep 17 00:00:00 2001 From: "mike.stackhouse" Date: Mon, 3 Jun 2024 19:50:41 +0000 Subject: [PATCH 08/11] Typos galore --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index c1e09be..fa2192c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,7 +28,7 @@ Imports: jsonvalidate (>= 1.3.1) Suggests: testthat (>= 2.1.0), - jsonlite (>= 1.8.0) + jsonlite (>= 1.8.0), knitr, haven, rmarkdown, From 57ecddc942e3325b8218fc263bb45808c9f8d2ed Mon Sep 17 00:00:00 2001 From: Michael Stackhouse Date: Thu, 20 Jun 2024 16:59:55 -0400 Subject: [PATCH 09/11] Update R/read_dataset_json.R Co-authored-by: Nicholas Masel <61123199+nicholas-masel@users.noreply.github.com> --- R/read_dataset_json.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/read_dataset_json.R b/R/read_dataset_json.R index a533559..a389558 100644 --- a/R/read_dataset_json.R +++ b/R/read_dataset_json.R @@ -48,7 +48,6 @@ read_dataset_json <- function(file) { ) } - # Read the file and convert to datasetjson object # Pull the object out with a lot of assumptions because the format has already From 2c649487b788aad940b52dccb28c3d590a8614a3 Mon Sep 17 00:00:00 2001 From: "mike.stackhouse" Date: Thu, 20 Jun 2024 21:07:26 +0000 Subject: [PATCH 10/11] remove suggested jsonlite --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index fa2192c..ce03ed7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,7 +28,6 @@ Imports: jsonvalidate (>= 1.3.1) Suggests: testthat (>= 2.1.0), - jsonlite (>= 1.8.0), knitr, haven, rmarkdown, From 922de649249f9d8a68e2ec72b2f308c6b37ab021 Mon Sep 17 00:00:00 2001 From: "mike.stackhouse" Date: Thu, 20 Jun 2024 22:27:52 +0000 Subject: [PATCH 11/11] Roll back R version add back jsonlite to suggests --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ce03ed7..2019222 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,12 +22,13 @@ License: Apache License (>= 2) LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 -Depends: R (>= 4.2) +Depends: R (>= 4.0) Imports: yyjsonr (>= 0.1.18), jsonvalidate (>= 1.3.1) Suggests: testthat (>= 2.1.0), + jsonlite (>= 1.8.0), knitr, haven, rmarkdown,