This functions is used to find information about data published by the ONS. Datasets are published in unique versions, which are categorized by edition. Available datasets are given an id. All available id can be viewed with ons_ids().

ons_get(
  id = NULL,
  edition = NULL,
  version = NULL,
  ons_read = getOption("onsr.read"),
  ...
)

ons_get_obs(id = NULL, edition = NULL, version = NULL, ...)

Arguments

id

[character] Id that represents a dataset.

edition

[character] A subset of the dataset representing a specific time period. For some datasets this edition can contain all time periods (all historical data). The latest version of this is displayed by default.

version

[character] A specific instance of the edition at a point in time. New versions can be published as a result of corrections, revisions or new data becoming available.

ons_read

[character]. Reading backend, one of readr, data.table or vroom.

...

Further arguments passed on the reading functions.

Value

A tibble with the dataset in tidy format.

Examples

# \donttest{ ons_get(id = "cpih01")
#> # A tibble: 55,305 x 7 #> v4_0 `mmm-yy` Time `uk-only` Geography cpih1dim1aggid Aggregate #> <dbl> <chr> <chr> <chr> <chr> <chr> <chr> #> 1 83.9 May-03 May-03 K02000001 United Ki… cpih1dim1G402… 04.2.0 Owner Occup… #> 2 54.7 May-96 May-96 K02000001 United Ki… cpih1dim1G110… 11.1 Catering serv… #> 3 68.5 Aug-99 Aug-99 K02000001 United Ki… cpih1dim1S101… 01.1.2 Meat #> 4 60.5 Feb-00 Feb-00 K02000001 United Ki… cpih1dim1S702… 07.2.4 Other servi… #> 5 81.4 Oct-89 Oct-89 K02000001 United Ki… cpih1dim1S903… 09.3.3 Gardens, pl… #> 6 100. Sep-15 Sep-15 K02000001 United Ki… cpih1dim1S120… 12.6.2 Other finan… #> 7 116. May-00 May-00 K02000001 United Ki… cpih1dim1G903… 09.3 Other recreat… #> 8 99.5 Aug-17 Aug-17 K02000001 United Ki… cpih1dim1S302… 03.2.0 Footwear in… #> 9 38 Mar-04 Mar-04 K02000001 United Ki… cpih1dim1G100… 10.0 Education #> 10 87.3 Mar-95 Mar-95 K02000001 United Ki… cpih1dim1S120… 12.1.2/3 Appliance… #> # … with 55,295 more rows
# Same dataset but older version ons_get(id = "cpih01", version = "5")
#> # A tibble: 55,977 x 7 #> v4_0 `mmm-yy` Time `uk-only` Geography cpih1dim1aggid Aggregate #> <dbl> <chr> <chr> <chr> <chr> <chr> <chr> #> 1 90.9 Jul-11 Jul-11 K02000001 United Ki… cpih1dim1G110… 11.1 Catering serv… #> 2 68.7 Feb-98 Feb-98 K02000001 United Ki… cpih1dim1S101… 01.1.2 Meat #> 3 94.9 Mar-12 Mar-12 K02000001 United Ki… cpih1dim1S802… 08.2.0 Telephone a… #> 4 84.9 Aug-93 Aug-93 K02000001 United Ki… cpih1dim1S120… 12.1.2/3 Appliance… #> 5 102. Dec-12 Dec-12 K02000001 United Ki… cpih1dim1S502… 05.2.0 Household T… #> 6 91.4 Apr-91 Apr-91 K02000001 United Ki… cpih1dim1S903… 09.3.3 Gardens, pl… #> 7 0 Jun-96 Jun-96 K02000001 United Ki… cpih1dim1S120… 12.4.0 Social Prot… #> 8 108. Mar-03 Mar-03 K02000001 United Ki… cpih1dim1S502… 05.2.0 Household T… #> 9 30.8 May-96 May-96 K02000001 United Ki… cpih1dim1G202… 02.2 Tobacco #> 10 85.3 Jun-99 Jun-99 K02000001 United Ki… cpih1dim1G505… 05.5 Tools and equ… #> # … with 55,967 more rows
# } # \donttest{ # Take only specific observations ons_get_obs("cpih01", geography = "K02000001", aggregate = "cpih1dim1A0", time = "Oct-11")
#> Fetched 1/1 (limit = 10000, offset = 0)
#> # A tibble: 1 x 1 #> observation #> <chr> #> 1 94.5
# Or can use a wildcard for the time ons_get_obs("cpih01", geography = "K02000001", aggregate = "cpih1dim1A0", time = "*")
#> Fetched 398/398 (limit = 10000, offset = 0)
#> # A tibble: 398 x 2 #> dimensions$Time$href dimensions$$id dimensions$$lab… observation #> <chr> <chr> <chr> <chr> #> 1 https://api.beta.ons.gov.uk/v1/c… May-04 May-04 77.9 #> 2 https://api.beta.ons.gov.uk/v1/c… May-13 May-13 98.2 #> 3 https://api.beta.ons.gov.uk/v1/c… Sep-16 Sep-16 101.5 #> 4 https://api.beta.ons.gov.uk/v1/c… May-88 May-88 48.0 #> 5 https://api.beta.ons.gov.uk/v1/c… Apr-18 Apr-18 105.5 #> 6 https://api.beta.ons.gov.uk/v1/c… Oct-92 Oct-92 62.5 #> 7 https://api.beta.ons.gov.uk/v1/c… Nov-17 Nov-17 104.7 #> 8 https://api.beta.ons.gov.uk/v1/c… Feb-04 Feb-04 77.2 #> 9 https://api.beta.ons.gov.uk/v1/c… Aug-08 Aug-08 87.1 #> 10 https://api.beta.ons.gov.uk/v1/c… Nov-93 Nov-93 63.8 #> # … with 388 more rows
# }