knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The goal of jabr is to browse, list, and fetch dataset from Open Data Jawa Barat right from R.
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")
This is a basic example which shows you how to solve a common problem:
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
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
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.