Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #22 #24

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.

7 changes: 6 additions & 1 deletion R/read_dataset_json.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-read_dataset_json.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
2 changes: 1 addition & 1 deletion vignettes/getting_started.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down