load_custom: A function for loading a custom dataset via HMRC's API.

View source: R/load_custom.R

load_customR Documentation

A function for loading a custom dataset via HMRC's API.

Description

A function for loading a custom dataset via HMRC's API.

Usage

load_custom(
  base_url = "https://api.uktradeinfo.com",
  endpoint,
  custom_search = "",
  request = 1,
  timer = NULL,
  skip_interval = NULL,
  output = "tibble",
  print_url = FALSE,
  debug = FALSE,
  use_proxy = FALSE,
  ...
)

Arguments

base_url

Base URL for use in API. Defaults to https://api.uktradeinfo.com.

endpoint

Endpoint for use in API. Takes a single character string with no default.

custom_search

Custom query. Takes a single character string with no default.

request

A non-negative integer value to keep track of the starting number of requests made. Defaults to zero. This can be increased in case you are making multiple requests using this function in succession and do not want to exceed the API limit (60 requests per minute).

timer

A non-negative integer value (seconds) to keep track of the time taken so far. Defaults to NULL. This can be increased in case you are making multiple requests using this function in succession and do not want to exceed the API limit (60 requests per minute).

skip_interval

Indicates the skip interval for paginated results. Defaults to NULL; this uses the skip parameter automatically generated by the API. Setting this to a different non-negative integer value is currently not supported.

output

A character specifying if a tibble ("tibble") or dataframe ("df") should be returned. Defaults to "tibble".

print_url

A logical. Defaults to FALSE. Setting this to TRUE will print the URL(s) used to load data to the console.

debug

A logical. Defaults to FALSE. Setting this to TRUE will print the number of datasets as they are being loaded as well as the elapsed time.

use_proxy

A logical. Defaults to FALSE. Setting this to TRUE will allow the use of a proxy connection using 'use_proxy()' from 'httr'.

...

Optional arguments to be passed along to 'use_proxy()' when using a proxy connection (by setting use_proxy to TRUE). See the 'httr' documentation for more details.

Value

Returns a dataframe or tibble containing the API response

Examples

## Not run: 
# Obtaining all exports of single malt Scotch whisky and bottled gin between
January 2000 and December 2020 via the OTS endpoint:

custom_search <- paste0(
  "?$filter= (FlowTypeId eq 2 or FlowTypeId eq 4)",
  " and (CommodityId eq 22083030 or CommodityId eq 22085011)",
  " and (MonthId ge 201001 and MonthId le 202012)"
  )

data <- load_custom(endpoint = "OTS", custom_search = custom_search)

# Note that there are more than 30,000 rows returned:

nrow(data)


## End(Not run)

pvdmeulen/uktrade documentation built on Feb. 18, 2025, 7:54 p.m.