Skip to contents

Search and get datasets that BPS distributes in JSONs. The API calls them dynamic tables.

  • bps_dataset() requests the dataset table. This table contains dataset IDs, which are needed to request datasets

  • bps_get_dataset() requests a dataset

  • bps_get_datasets() requests multiple datasets

Usage

bps_dataset(
  subject_id = NULL,
  vertical_var_group_id = NULL,
  domain_id = "0000",
  page = NULL,
  lang = c("ind", "eng")
)

bps_get_dataset(
  dataset_id,
  vertical_var_id = NULL,
  derived_var_id = NULL,
  year_id = NULL,
  period_id = NULL,
  domain_id = "0000",
  lang = c("ind", "eng"),
  keep = "none"
)

bps_get_datasets(
  dataset_id,
  domain_id = "0000",
  lang = c("ind", "eng"),
  keep = "none"
)

Arguments

subject_id

The subject ID. Use bps_subject() to see the list of subject IDs.

vertical_var_group_id

The vertical variable group ID. Use bps_vertical_var() to see the list of vertical variable group IDs.

domain_id

The domain ID of a BPS bureau. Defaults to "0000", which is the domain ID of the central bureau. Use bps_domain() to see the list of domain IDs.

page

The page number of the result. Defaults to page one. Set to Inf to request all pages.

lang

The result's language. Must be either "ind" for Indonesian or "eng" for English. Defaults to Indonesian.

dataset_id

The dataset ID. To request multiple datasets, supply a vector of the IDs to bps_get_datasets(). Use bps_dataset() to see the list of dataset IDs.

vertical_var_id

The vertical variable ID. Use bps_vertical_var() to see the list of vertical variable IDs.

derived_var_id

The derived variable ID. Use bps_derived_var() to see the list of derived variable IDs.

year_id

The year ID. Use bps_year() to see the list of year IDs.

period_id

The period ID. Use bps_period() to see the list of period IDs.

keep

ID columns to keep. Defaults to "none", which drops all of them. Set to "all" to keep all ID columns. Otherwise, must be "vertical_var_id", "derived_var_id", "year_id" or "period_id". To keep multiple ID columns, supply a vector of them.

Value

  • bps_dataset() returns a tibble containing dataset IDs and titles.

  • bps_get_dataset() returns a tibble with the bpsr_tbl subclass, which has a metadata attribute. Use bps_metadata() to read it.

  • bps_get_datasets() returns a list with the bpsr_multiple_tbl class, which contains tibbles with the bpsr_tbl subclass.

Request filter

Filter a request by multiple values of vertical_var_id, derived_var_id, year_id or period_id by supplying a vector of the IDs, to bps_get_dataset(). For example, vertical_var_id = c("1100", "1200").

For year_id and period_id, filter by a range of values by concatenating the start and the end of the range using a colon, e.g. year_id = "118:121" for observations from 2018 to 2021.

Examples

# Get the dataset on consumer price index of food category
bps_get_dataset("1905", lang = "eng")
#> # A tibble: 16,852 × 5
#>    vertical_var  derived_var                   year period      var
#>    <chr>         <chr>                        <int> <chr>     <dbl>
#>  1 KOTA MEULABOH Foods, Beverages and Tobacco  2020 January    112.
#>  2 KOTA MEULABOH Foods, Beverages and Tobacco  2020 February   111.
#>  3 KOTA MEULABOH Foods, Beverages and Tobacco  2020 March      112.
#>  4 KOTA MEULABOH Foods, Beverages and Tobacco  2020 April      111.
#>  5 KOTA MEULABOH Foods, Beverages and Tobacco  2020 May        113.
#>  6 KOTA MEULABOH Foods, Beverages and Tobacco  2020 June       112.
#>  7 KOTA MEULABOH Foods, Beverages and Tobacco  2020 July       111.
#>  8 KOTA MEULABOH Foods, Beverages and Tobacco  2020 August     113.
#>  9 KOTA MEULABOH Foods, Beverages and Tobacco  2020 September  113.
#> 10 KOTA MEULABOH Foods, Beverages and Tobacco  2020 October    114.
#> # ℹ 16,842 more rows
#> # ℹ Read the metadata with `bps_metadata()`

# Get some Human Development Index datasets
bps_get_datasets(c("414", "415", "416", "417"), lang = "eng")
#> <bpsr_multiple_datasets>
#> List of 4
#>  $ 414: bpsr_tbl [7,125 × 5] (S3: bpsr_tbl/tbl_df/tbl/data.frame)
#>   ..$ vertical_var: chr [1:7125] "ACEH" ...
#>   ..$ derived_var : chr [1:7125] NA ...
#>   ..$ year        : int [1:7125] 2010 2011 ...
#>   ..$ period      : chr [1:7125] "Annual" ...
#>   ..$ var         : num [1:7125] 69.1 ...
#>  $ 415: bpsr_tbl [7,067 × 5] (S3: bpsr_tbl/tbl_df/tbl/data.frame)
#>   ..$ vertical_var: chr [1:7067] "ACEH" ...
#>   ..$ derived_var : chr [1:7067] NA ...
#>   ..$ year        : int [1:7067] 2010 2011 ...
#>   ..$ period      : chr [1:7067] "Annual" ...
#>   ..$ var         : num [1:7067] 8.28 8.32 ...
#>  $ 416: bpsr_tbl [7,067 × 5] (S3: bpsr_tbl/tbl_df/tbl/data.frame)
#>   ..$ vertical_var: chr [1:7067] "ACEH" ...
#>   ..$ derived_var : chr [1:7067] NA ...
#>   ..$ year        : int [1:7067] 2010 2011 ...
#>   ..$ period      : chr [1:7067] "Annual" ...
#>   ..$ var         : int [1:7067] 7934 8044 ...
#>  $ 417: bpsr_tbl [7,077 × 5] (S3: bpsr_tbl/tbl_df/tbl/data.frame)
#>   ..$ vertical_var: chr [1:7077] "ACEH" ...
#>   ..$ derived_var : chr [1:7077] NA ...
#>   ..$ year        : int [1:7077] 2010 2011 ...
#>   ..$ period      : chr [1:7077] "Annual" ...
#>   ..$ var         : num [1:7077] 12.9 ...