MyNixOS website logo
Description

Handle 'JSON-stat' Format in R.

Handle 'JSON-stat' format (<https://json-stat.org>) in R. Not all features are supported, especially the extensive metadata features of 'JSON-stat'.

rjstat: read and write JSON-stat with R

Build Status Coverage Status rstudio mirror downloads cran version

Read and write data sets in the JSON-stat format.

Installation:

From CRAN (most people use this):

install.packages('rjstat')

From github (development version):

library(devtools)
install_github("ajschumacher/rjstat")

Usage:

library(rjstat)

oecd.canada.url <- "https://json-stat.org/samples/oecd-canada.json"

# Read from JSON-stat to a list of data frames:
results <- fromJSONstat(readLines(oecd.canada.url))
names(results)

## [1] "Unemployment rate in the OECD countries 2003-2014"
## [2] "Population by sex and age group. Canada. 2012"

# You can also read in using the typically terser IDs rather than labels.
results <- fromJSONstat(readLines(oecd.canada.url), naming="id")
names(results)

## [1] "oecd"   "canada"


# Convert from a list of data frames to a JSON-stat string.
# (The data frames must have exactly one value column.)
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))

## {"version":"2.0","class":"collection","link":{"item":[{"class":"dataset","id

# You can successfully convert back and forth, but only for the features that
# make sense in both R and JSON-stat.
head(fromJSONstat(irisJSONstat)[[1]])

##   Species Specimen     variable value
## 1  setosa        1 Sepal.Length   5.1
## 2  setosa        1  Sepal.Width   3.5
## 3  setosa        1 Petal.Length   1.4
## 4  setosa        1  Petal.Width   0.2
## 5  setosa        2 Sepal.Length   4.9
## 6  setosa        2  Sepal.Width   3.0
Metadata

Version

0.4.3

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows