load_ots: A function for loading OTS data via HMRC's API.

View source: R/load_ots.R

load_otsR Documentation

A function for loading OTS data via HMRC's API.

Description

A function for loading OTS data via HMRC's API.

Usage

load_ots(
  month = NULL,
  flow = NULL,
  commodity = NULL,
  sitc = NULL,
  country = NULL,
  region = NULL,
  uk_port = NULL,
  suppression = NULL,
  join_lookup = TRUE,
  print_url = FALSE,
  output = "tibble",
  skip_interval = NULL,
  use_proxy = FALSE,
  ...
)

Arguments

month

The month(s) to be loaded in the form of a vector of two integers (YYYYMM), where the first element is the minimum date, and second the maximum date. Defaults to NULL (all months).

flow

The trade flow to be loaded. Takes one ore more integers (1, 2, 3, and/or 4), where 1 is EU imports, 2 is EU exports, 3 is non-EU imports, and 4 is non-EU exports. Defaults to NULL (all flows).

commodity

One or more HS2, HS4, HS6, or CN8 commodity codes in the form of a numeric or character vector. Defaults to NULL (all commodities). Any missing leading zeros will be automatically added.

sitc

One or more SITC1, SITC2, SITC3, SITC4, or SITC5 commodity codes in the form of a character vector. Defaults to NULL (all commodities).

country

One or more destination or origin countries by their 2-letter ISO code. Defaults to NULL (all countries).

region

One or more destination or origin regions. Defaults to NULL (all regions). Takes one or more of the following broad categories: "Asia and Oceania", "Eastern Europe exc EU", "European Union", "Latin America and Caribbean", "Middle East and N Africa", "North America", "Sub-Saharan Africa", "Western Europe exc EU", "Western Europe exc EC", "Low Value Trade", "Stores and Provisions", and/or "Confidential Region".

uk_port

One or more departure or arrival ports by their three-letter code (only available for trade with non-EU countries prior to 2021, and all trade post-2021). Defaults to NULL (all ports in the UK).

suppression

One or more suppression codes. Takes one or more integers between 1 and 5 (see HMRC API guidance for information). Defaults to NULL (all available results).

join_lookup

A logical value indicating whether results should be joined with lookups from the API. Defaults to TRUE. Setting to FALSE will return a smaller but less human-readable dataframe containing only codes.

print_url

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

output

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

skip_interval

Passed to load_custom(). 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.

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

Examples

## Not run: 
# Obtaining all trade of single malt Scotch whisky and bottled gin between in
# 2019 via the OTS endpoint:

load_ots(month = c(201901, 201912), commodity = c(22083030, 22085011))


## End(Not run)

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