Learn R Programming

PxWebApiData (version 1.9.0)

get_api_data: PX-Web Data by API (GET)

Description

A function to read PX-Web data into R via API using GET.

Usage

get_api_data(
  url,
  return_dataset = NULL,
  make_na_status = TRUE,
  verbose_print = FALSE,
  use_ensure_json_stat2 = "auto"
)

get_api_data_1(..., return_dataset = 1)

get_api_data_2(..., return_dataset = 2)

get_api_data_12(..., return_dataset = 12)

Value

A data frame, or a list of data frames, depending on the input and parameters.

Arguments

url

A PxWeb API URL to data.

return_dataset

Possible non-NULL values are 1, 2 and 12. Then a single data set is returned as a data frame.

make_na_status

When TRUE and when dataPackage is "rjstat" and when missing entries in value, the function tries to add an additional variable, named NAstatus, with status codes. An explanation of these status codes is provided in the note part of the comment attribute, i.e. what you get with note(). See the bottom example.

verbose_print

When TRUE, printing to console

use_ensure_json_stat2

TRUE, FALSE, or "auto" (default). If "auto", the URL is modified by ensure_json_stat2() only when "/v2/" is detected in the URL.

...

Additional arguments passed to get_api_data().

Examples

Run this code
url <- paste0(
  "https://data.ssb.no/api/pxwebapi/v2/tables/03013/data?lang=en",
  "&valueCodes[Konsumgrp]=??",
  "&valueCodes[ContentsCode]=KpiIndMnd",
  "&valueCodes[Tid]=top(2)"
)
  
get_api_data_2(url)    
  

Run the code above in your browser using DataLab