---
title: "Quickstart"
author:
- "Kim Seonghyun"
date: "`r Sys.Date()`"
output: 
  html_document:
      toc: true
      toc_float: true
      theme: flatly
vignette: >
  %\VignetteIndexEntry{quickstart}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, echo = FALSE, message = FALSE}
library(jsonstat)
```

### Installation

Either you try stable CRAN version

```{r, eval = F}
install.packages("jsonstat")
```

Or unstable development version

```{r, eval = F}
devtools::install_github("zedoul/jsonstat")
```

You'll need to use `library` to load as follows:

```{r, eval = F}
library(jsonstat)
```

### Introduction

`jsonstat` is an R package for converting data frame into `JSON-stat` format (https://json-stat.org/), which is a simple lightweight 'JSON' format for data dissemination.

### Example

A minimal example would be like:

```{r}
library(jsonstat)
library(dplyr)

x <- read.csv2("galicia.csv", sep = ",")

.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")

.extension <- list(id = 3,
                   name = "asdfdsfsd",
                   lol = TRUE,
                   arr = 1:5,
                   training = list(name = "training",
                                   from = "xxxx",
                                   to = "yyyy"),
                   testing = list(name = "testing",
                                  from = "xxxx",
                                  to = "yyyy"))

.dataset <- as.dataset(x, .plan,
              label = paste("Population by province of residence,",
                            "place of birth, age, gender and year",
                            "in Galicia"),
              href = "https://github.com/zedoul/jsonstat",
              extension = .extension)

.collection <- as.collection(.dataset, label = "Comparison",
                             href = "https://github.com/zedoul/jsonstat")

.jsonstat <- toJSON(.collection)
```

You can also check its output via [official website](https://json-stat.org/format/viewer/?uri=https%3A%2F%2Fraw.githubusercontent.com%2Fzedoul%2Fjsonstat%2Fmaster%2Ftests%2Ftestthat%2Foutput%2Fgalicia_jsonstat.json).

