Package 'rjstat'

Title: Handle 'JSON-stat' Format in R
Description: Handle 'JSON-stat' format (<https://json-stat.org>) in R. Not all features are supported, especially the extensive metadata features of 'JSON-stat'.
Authors: Aaron Schumacher, Håkon Malmedal, Måns Magnusson
Maintainer: Aaron Schumacher <[email protected]>
License: MIT + file LICENSE
Version: 0.4.3
Built: 2024-10-30 04:30:05 UTC
Source: https://github.com/ajschumacher/rjstat

Help Index


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) labels or (shorter) ids

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 ids of jsonstat objects.

Usage

id(x)

id(x) <- value

Arguments

x

a jsonstat_dataset object

value

a character vector of up to the same length as id(x).


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.


status accessors of jsonstat objects

Description

Access and change statuss of jsonstat objects.

Usage

status(x)

status(x) <- value

Arguments

x

a jsonstat_dataset object

value

a character vector of up to the same length as as.vector(x) or a named list with index as vector names.


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 toJSON

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)