Introduction

This package provides easy access to the API provided by Open Government Data Platform - India to download datasets from R. Here's the list of Datasets available through API.

Basic Usage

library(ogdindiar)

When calling OGD India API, at minimum, you need to provide 2 parameters.

Resource id for the datasets can be found on the data specific page on the data portal. For example, this page has the resource id information for Annual And Seasonal Mean Temperature Of India. The resource is a string that's part of Datastore API URL.

The main function this package provides is fetch_data(). Once you have figured out the resource id, you can download that dataset as follows:

mean_temp_data = fetch_data(res_id = "98fe9271-a59d-4834-b05b-fd5ddb94ac01")

This function returns a list of 2 elements.

knitr::kable(head(mean_temp_data[[1]]))
knitr::kable(mean_temp_data[[2]])

Advanced Usage

Instead of downloading entire datasets you can conditionally download specific data elements. This functionality is achieved using additional arguments to fetch_data() function. Currently you can use -

Following example illustrates this -

mean_temp_25 = fetch_data(res_id = "98fe9271-a59d-4834-b05b-fd5ddb94ac01",
                        filter = c("annual" = "25"),
                        select = c("year", "annual", "jan_feb", "mar_may", "jun_sep", "oct_dec"),
                        sort = c("jan_feb" = "asc", "mar_may" = "desc")
                        )

The returned dataset -

knitr::kable(head(mean_temp_25[[1]]))

Metadata about the returned dataset

knitr::kable(mean_temp_25[[2]])

There's one more argument that is passed to fetch_data() function, field_type_correction. The data fetch process inadvertently treats all the columns as character. The default setting field_type_correction = TRUE converts these columns back to numeric type based on accompanying metadata.



steadyfish/ogdindiar documentation built on May 30, 2019, 10:43 a.m.