knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

jabr

The goal of jabr is to browse, list, and fetch dataset from Open Data Jawa Barat right from R.

Installation

You can install the released version of jabr from CRAN with:

install.packages("jabr")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("aswansyahputra/jabr")

Examples

This is a basic example which shows you how to solve a common problem:

Fetch single dataset

library(jabr)

(x <- jabr_list_dataset())

# suppose that we want to get dataset about "Jumlah Desa Siaga Di Provinsi Jawa Barat 2018".
# Id of this data is "88ef59c5".

jabr_fetch("88ef59c5")

## optionally, you can also remove the 'title' column
desa_siaga <- jabr_fetch("88ef59c5", keep_title = FALSE)
desa_siaga

Fetch multiple datasets

library(jabr)
library(dplyr)
library(stringr)
library(tidyr)

(x <- jabr_list_dataset())


# suppose that we want to get the datasets about "Angka Harapan Hidup".
# There are several datasets available in the list (one dataset per observation year).

## Step 1. List the ids of datasets that fall within same category.
## We can check and write the ids manualy, or using filtering technique.
ids <- 
  x %>%
  dplyr::filter(stringr::str_detect(title, "Angka Harapan Hidup")) %>% 
  dplyr::pull(id)
ids

## Step 2. Fetch the datasets using the ids.
ahh_jabar_raw <- 
  jabr_fetch(id = ids)
ahh_jabar_raw

## Step 3. Expand/unnest the datasets.
ahh_jabar <- 
  ahh_jabar_raw %>% 
  tidyr::unnest(dataset)
ahh_jabar

## Step 4. (optional) Perform some data cleaning.
ahh_jabar <- 
  ahh_jabar %>% 
  tidyr::extract(title, "tahun", "(\\d{4})", convert = TRUE)
ahh_jabar

Fetch multiple datasets (simple ways)

We will replicate the previous section, but by using a new and straighforward function.

library(jabr)
library(tidyr)

(x <- jabr_list_dataset())


# suppose that we want to get the datasets about "Angka Harapan Hidup".
# There are several datasets available in the list (one dataset per observation year). Those dataset falls within the same group_id, so we can use jabr_fetch_group() to fetch them.

## Step 1. Fetch the datasets using group_id ("ffa4dc21").
ahh_jabar_raw <- 
  jabr_fetch_group(group_id = "ffa4dc21")
ahh_jabar_raw

## Step 2. Expand/unnest the datasets.
ahh_jabar <- 
  ahh_jabar_raw %>% 
  tidyr::unnest(dataset)
ahh_jabar

## Step 3. (optional) Perform some data cleaning.
ahh_jabar <- 
  ahh_jabar %>% 
  tidyr::extract(title, "tahun", "(\\d{4})", convert = TRUE)
ahh_jabar


aswansyahputra/jabr documentation built on Dec. 27, 2019, 2:20 a.m.