Title: | Handle 'JSON-stat' Format in R |
Version: | 0.4.3 |
Author: | Aaron Schumacher, Håkon Malmedal, Måns Magnusson |
Maintainer: | Aaron Schumacher <ajschumacher@gmail.com> |
Description: | Handle 'JSON-stat' format (https://json-stat.org) in R. Not all features are supported, especially the extensive metadata features of 'JSON-stat'. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
URL: | https://github.com/ajschumacher/rjstat |
BugReports: | https://github.com/ajschumacher/rjstat/issues |
Imports: | jsonlite (≥ 0.9.8), checkmate (≥ 1.7.0) |
Suggests: | testthat (≥ 1.0.0), reshape (≥ 0.7) |
RoxygenNote: | 7.2.3 |
NeedsCompilation: | no |
Packaged: | 2023-09-04 16:37:33 UTC; hmalm |
Repository: | CRAN |
Date/Publication: | 2023-09-05 09:20:02 UTC |
Read and write JSON-stat data sets
Description
JSON-stat is a JSON format for data dissemination. The rjstat package converts data frames to and from this format. The extensive metadata features of JSON-stat are not supported.
Convert to jsonlite json object
Description
Convert to jsonlite json object
Usage
as.json(x, ...)
Arguments
x |
an object to coerce to a json object. |
... |
additional arguments to be passed to or from methods. |
Details
Currently only methods for jsonstat
objects are implemented.
Create a JSON-stat object
Description
Create a JSON-stat object
Usage
as.jsonstat(x)
is.jsonstat(x)
is.jsonstat_dataset(x)
is.jsonstat_collection(x)
is.jsonstat_dimension(x)
Arguments
x |
a JSON-stat string, URL or file |
Value
a JSON-stat object with subclass dataset, dimension or collection
Examples
file_path <- system.file("extdata", "oecd.json", package = "rjstat")
x <- as.jsonstat(file_path)
print(x)
is.jsonstat(x)
is.jsonstat_dataset(x)
is.jsonstat_dimension(x)
Convert JSON-stat format to data frame(s)
Description
This function takes a JSON-stat format response and returns a data frame or a
list of data frames, with columns for each dimension and one value
column.
Usage
fromJSONstat(x, naming = "label", use_factors = FALSE, silent = FALSE)
Arguments
x |
JSON-stat format response, or path or URL to such a response |
naming |
whether to use (longer) |
use_factors |
whether dimension categories should be factors or character objects |
silent |
suppress warnings |
Value
For responses with class dataset
: A data frame. For responses
with class collection
: An unnamed list of one or more lists or data
frames. For responses with class bundle
: A named list of one or more
data frames.
Examples
## Not run:
oecd.canada.url <- "https://json-stat.org/samples/oecd-canada.json"
results <- fromJSONstat(oecd.canada.url)
names(results)
## End(Not run)
id
accessors of jsonstat
objects
Description
Access and change id
s of jsonstat objects.
Usage
id(x)
id(x) <- value
Arguments
x |
a |
value |
a character vector of up to the same length as |
status
accessors of jsonstat
objects
Description
Access and change status
s of jsonstat objects.
Usage
status(x)
status(x) <- value
Arguments
x |
a |
value |
a character vector of up to the same length as |
Convert data frame(s) to JSON-stat format
Description
This function takes a data frame or list of data frames and returns
a string representation in JSON-stat format. The input data frame(s)
must be in maximally long tidy format: with only one value
column and all other columns representing dimensions.
Usage
toJSONstat(x, value = "value", ...)
Arguments
x |
a data frame or list of data frames |
value |
name of value column |
... |
arguments passed on to |
Value
For a data frame: A JSON-stat format response with class
dataset
. For a list of data frames: A JSON-stat format response with
class collection
.
Examples
library(reshape)
irises <- melt(cbind(iris, Specimen=rep(1:50, 3)),
id.vars=c("Species", "Specimen"))
irisJSONstat <- toJSONstat(list(iris=irises))
cat(substr(irisJSONstat, 1, 76))
# Add indentation whitespace
toJSONstat(as.data.frame(Titanic), value = "Freq", pretty = TRUE)
Function to validate json stat
Description
Now this is just a simple light-weight validation. Hopefully this can be complemented with a real json stat schema validator.
Usage
validate_jsonstat(x)