Title: | Interface to 'JSON-stat' |
---|---|
Description: | Interface to 'JSON-stat' <https://json-stat.org/>, a simple lightweight 'JSON' format for data dissemination. |
Authors: | Kim Seonghyun [aut, cre] |
Maintainer: | Kim Seonghyun <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.2 |
Built: | 2025-02-18 04:10:55 UTC |
Source: | https://github.com/cran/jsonstat |
Convert data set into JSON-stat collection
as.collection(..., label = "", href = "", src = NULL, extension = NULL, updated = NULL)
as.collection(..., label = "", href = "", src = NULL, extension = NULL, updated = NULL)
... |
a named list, the function creates a collection based on user input like the same way as 'list'. |
label |
label of dataset |
href |
href of dataset, "" by default |
src |
source of dataset, NULL by default |
extension |
user data, NULL by default |
updated |
a timestamp for data, NULL by default |
Convert data frame into JSON-stat dataset
as.dataset(x, .plan, label, href = "", src = NULL, extension = NULL, updated = NULL)
as.dataset(x, .plan, label, href = "", src = NULL, extension = NULL, updated = NULL)
x |
data frame |
.plan |
compress plan |
label |
label of dataset |
href |
href of dataset, "" by default |
src |
source of dataset, NULL by default |
extension |
user data, NULL by default |
updated |
a timestamp for data, NULL by default |
This function marks atomic vectors in given list as a singleton, so that it will not turn into an 'array' when encoded into JSON.
autounbox(.list)
autounbox(.list)
.list |
a list contains atomic vectors |
This function constructs a plan to compress data frame into jsonstat
compress_plan(dim_name, role_name = c("time", "geo", "metric", "classification", "value"), label = NULL)
compress_plan(dim_name, role_name = c("time", "geo", "metric", "classification", "value"), label = NULL)
dim_name |
name of dimension |
role_name |
role of dimension |
label |
label of dimension |
jsonstat.compress.plan
object
library(jsonstat) .plan <- compress_plan("place.of.birth", "geo", "Place of Birth")
library(jsonstat) .plan <- compress_plan("place.of.birth", "geo", "Place of Birth")
Create dimension object
dimension(.plan, dim_name, role_name, label)
dimension(.plan, dim_name, role_name, label)
.plan |
|
dim_name |
name of dimension |
role_name |
role of dimension |
label |
label of dimension |
jsonstat.compress.plan
object
This function adds another dimension into compress plan
## S3 method for class 'jsonstat.compress.plan' dimension(.plan, dim_name, role_name = c("time", "geo", "metric", "classification", "value"), label = NULL)
## S3 method for class 'jsonstat.compress.plan' dimension(.plan, dim_name, role_name = c("time", "geo", "metric", "classification", "value"), label = NULL)
.plan |
|
dim_name |
name of dimension |
role_name |
role of dimension |
label |
label of dimension |
jsonstat.compress.plan
object
library(jsonstat) .plan <- compress_plan("place.of.birth", "geo", "Place of Birth") .plan <- dimension(.plan, "age.group", "classification", "Age Group")
library(jsonstat) .plan <- compress_plan("place.of.birth", "geo", "Place of Birth") .plan <- dimension(.plan, "age.group", "classification", "Age Group")
Galicia data
galicia
galicia
a data frame
galicia
galicia
jsonstat provides useful functions to work with JSON-stat format.
Maintainer: Kim Seonghyun [email protected]
Useful links:
Convert JSON-stat object into JSON-stat JSON string
toJSON(x, auto_unbox)
toJSON(x, auto_unbox)
x |
JSON-stat object |
auto_unbox |
this flag marks atomic vectors in given list as a singleton, so it will not turn into an 'array' when encoded into JSON. FALSE by default. |
JSON output
Convert JSON-stat collection into JSON
## S3 method for class 'jsonstat.collection' toJSON(x, auto_unbox = F)
## S3 method for class 'jsonstat.collection' toJSON(x, auto_unbox = F)
x |
JSON-stat collection |
auto_unbox |
this flag marks atomic vectors in given list as a singleton, so it will not turn into an 'array' when encoded into JSON. FALSE by default. |
JSON output
library(jsonstat) library(dplyr) .plan <- compress_plan("place.of.birth", "geo", "Place of Birth") %>% dimension("age.group", "classification", "Age Group") %>% dimension("gender", "classification", "Gender") %>% dimension("year", "time", "Year") %>% dimension("province.of.residence", "geo", "Province of Residence") %>% dimension("concept", "metric", "Concept") %>% dimension("value", "value", "value") .dataset <- as.dataset(galicia, .plan, label = paste("Population by province of residence,", "place of birth, age, gender and year", "in Galicia"), href = "https://github.com/zedoul/jsonstat") .collection <- as.collection(.dataset, label = "Comparison", href = "https://github.com/zedoul/jsonstat") .jsonstat <- toJSON(.collection)
library(jsonstat) library(dplyr) .plan <- compress_plan("place.of.birth", "geo", "Place of Birth") %>% dimension("age.group", "classification", "Age Group") %>% dimension("gender", "classification", "Gender") %>% dimension("year", "time", "Year") %>% dimension("province.of.residence", "geo", "Province of Residence") %>% dimension("concept", "metric", "Concept") %>% dimension("value", "value", "value") .dataset <- as.dataset(galicia, .plan, label = paste("Population by province of residence,", "place of birth, age, gender and year", "in Galicia"), href = "https://github.com/zedoul/jsonstat") .collection <- as.collection(.dataset, label = "Comparison", href = "https://github.com/zedoul/jsonstat") .jsonstat <- toJSON(.collection)
Convert JSON-stat dataset into JSON
## S3 method for class 'jsonstat.dataset' toJSON(x, auto_unbox = F)
## S3 method for class 'jsonstat.dataset' toJSON(x, auto_unbox = F)
x |
JSON-stat dataset |
auto_unbox |
this flag marks atomic vectors in given list as a singleton, so it will not turn into an 'array' when encoded into JSON. FALSE by default. |
JSON output
library(jsonstat) library(dplyr) .plan <- compress_plan("place.of.birth", "geo", "Place of Birth") %>% dimension("age.group", "classification", "Age Group") %>% dimension("gender", "classification", "Gender") %>% dimension("year", "time", "Year") %>% dimension("province.of.residence", "geo", "Province of Residence") %>% dimension("concept", "metric", "Concept") %>% dimension("value", "value", "value") .dataset <- as.dataset(galicia, .plan, label = paste("Population by province of residence,", "place of birth, age, gender and year", "in Galicia"), href = "https://github.com/zedoul/jsonstat") .jsonstat <- toJSON(.dataset)
library(jsonstat) library(dplyr) .plan <- compress_plan("place.of.birth", "geo", "Place of Birth") %>% dimension("age.group", "classification", "Age Group") %>% dimension("gender", "classification", "Gender") %>% dimension("year", "time", "Year") %>% dimension("province.of.residence", "geo", "Province of Residence") %>% dimension("concept", "metric", "Concept") %>% dimension("value", "value", "value") .dataset <- as.dataset(galicia, .plan, label = paste("Population by province of residence,", "place of birth, age, gender and year", "in Galicia"), href = "https://github.com/zedoul/jsonstat") .jsonstat <- toJSON(.dataset)