From 5145fd7c18f2c53dd4a7420f883e69f69c9c7c15 Mon Sep 17 00:00:00 2001 From: "mike.stackhouse" Date: Tue, 10 Oct 2023 13:54:15 +0000 Subject: [PATCH 1/2] Update #22 --- R/read_dataset_json.R | 7 ++++++- tests/testthat/test-read_dataset_json.R | 9 +++++++++ vignettes/getting_started.Rmd | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/R/read_dataset_json.R b/R/read_dataset_json.R index 5f5fa2b..1ffa313 100644 --- a/R/read_dataset_json.R +++ b/R/read_dataset_json.R @@ -24,9 +24,14 @@ read_dataset_json <- function(file) { if (path_is_url(file)) { + # Url? file_contents <- read_from_url(file) - } else { + } else if (file.exists(file)) { + # File on disk? file_contents <- readLines(file) + } else { + # Direct file contents? + file_contents <- file } # Validate the input file against the schema diff --git a/tests/testthat/test-read_dataset_json.R b/tests/testthat/test-read_dataset_json.R index 0394fae..7057d25 100644 --- a/tests/testthat/test-read_dataset_json.R +++ b/tests/testthat/test-read_dataset_json.R @@ -60,3 +60,12 @@ test_that("Dataset JSON can be read from a URL", { expect_equal(from_disk, from_url) }) + +test_that("Dataset JSON can be read from imported string", { + ds_json <- dataset_json(iris[1:5, ], "IG.IRIS", "IRIS", "Iris", iris_items) + js <- write_dataset_json(ds_json, pretty=TRUE) + expect_silent(dat <- read_dataset_json(js)) + x <- iris + x[5] <- as.character(x[[5]]) + expect_equal(x[1:5, ], dat, ignore_attr=TRUE) +}) diff --git a/vignettes/getting_started.Rmd b/vignettes/getting_started.Rmd index 50404fb..97d344c 100644 --- a/vignettes/getting_started.Rmd +++ b/vignettes/getting_started.Rmd @@ -44,7 +44,7 @@ iris_items This data frame has 7 columns, 4 of which are strictly required. This is defined by the [CDISC Dataset JSON Specification](https://www.cdisc.org/dataset-json). -| **Attribute** | **Requirement** | **Description** | +| **Attribute** | **Requirement** | **Description** | |---------------|-----------------|--------------------------------------------------------------------------------------------------------------------------------| | OID | Required | OID of a variable (must correspond to the variable OID in the Define-XML file) | | name | Required | Variable name | From 19410180c4a8c330c16c309e97e34cd66eaa8956 Mon Sep 17 00:00:00 2001 From: "mike.stackhouse" Date: Tue, 10 Oct 2023 13:54:30 +0000 Subject: [PATCH 2/2] Formatting --- NEWS.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index a0c92c1..103096c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,12 +1,11 @@ # datasetjson 0.1.0 -- Capability to read and validate Dataset JSON files from URLs has been added (#8) -- Remove autoset of fileOID using output path (#3) -- Don't auto-populate optional attributes with NA (#16) -- Push dependency versions back (#18) -- Default `pretty` parameter on `write_dataset_json()` to false (#20) +- Capability to read and validate Dataset JSON files from URLs has been added (#8) +- Remove autoset of fileOID using output path (#3) +- Don't auto-populate optional attributes with NA (#16) +- Push dependency versions back (#18) +- Default `pretty` parameter on `write_dataset_json()` to false (#20) # datasetjson 0.0.1 Initial development version of datasetjson, introducing core objects, readers and writers. -