get_api_data: PX-Web Data by API (GET)

View source: R/api_data.R

get_api_dataR Documentation

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)

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().

Value

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

Examples

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)    
  

PxWebApiData documentation built on Sept. 9, 2026, 5:07 p.m.