diff --git a/.Rbuildignore b/.Rbuildignore index b708ffe..ef87ee0 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,4 @@ +^CODE_OF_CONDUCT\.md$ ^.*\.Rproj$ ^\.Rproj\.user$ ^README\.Rmd$ diff --git a/inst/doc/introduction.R b/inst/doc/introduction.R deleted file mode 100644 index 95f0749..0000000 --- a/inst/doc/introduction.R +++ /dev/null @@ -1,84 +0,0 @@ -## ---- echo=TRUE---------------------------------------------------------- -library(nomisr) -x <- nomis_data_info() -head(x) - -## ---- echo=TRUE---------------------------------------------------------- -y <- nomis_data_info("NM_893_1") - -tibble::glimpse(y) - -## ---- echo=TRUE---------------------------------------------------------- -library(dplyr, warn.conflicts = F) - -y$annotations.annotation %>% class() - -y$annotations.annotation %>% length() - -y$annotations.annotation[[1]] %>% class() - -y %>% pull(annotations.annotation) %>% class() - -y %>% pull(annotations.annotation) %>% .[[1]] %>% class() - -y %>% pull(annotations.annotation) %>% purrr::pluck() %>% class() - -## Unnesting list columns -y %>% tidyr::unnest(annotations.annotation) %>% glimpse() - -## ---- echo=TRUE---------------------------------------------------------- -a <- nomis_search(name = '*jobseekers*', keywords = 'Claimants') - -tibble::glimpse(a) - -a %>% tidyr::unnest(components.attribute) %>% glimpse() - -b <- nomis_search(keywords = c('Claimants', '*Year*')) - -tibble::glimpse(b) - -b %>% tidyr::unnest(components.attribute) %>% glimpse() - - -## ---- echo=TRUE---------------------------------------------------------- -q <- nomis_overview("NM_1650_1") - -q %>% tidyr::unnest(name) %>% glimpse() - - -## ---- echo=TRUE---------------------------------------------------------- - s <- nomis_overview("NM_1650_1", select = c("units", "keywords")) - - s %>% tidyr::unnest(name) %>% glimpse() - -## ---- echo=TRUE---------------------------------------------------------- - - a <- nomis_get_metadata(id = "NM_893_1") - - print(a) - -## ---- echo=TRUE---------------------------------------------------------- - b <- nomis_get_metadata(id = "NM_893_1", concept = "GEOGRAPHY") - - print(b) - -## ---- echo=TRUE---------------------------------------------------------- - c <- nomis_get_metadata(id = "NM_893_1", concept = "geography", type = "type") - - print(c) - -## ---- echo=TRUE---------------------------------------------------------- - d <- nomis_get_metadata(id = "NM_893_1", concept = "geography", type = "TYPE460") - - print(d) - -## ---- echo=TRUE---------------------------------------------------------- - z <- nomis_get_data(id = "NM_893_1", time = "latest", geography = "TYPE266") - -print(z) - -## ---- echo=TRUE---------------------------------------------------------- - x <- nomis_get_data(id = "NM_893_1", time = "latest", geography = c("1929380119", "1929380120")) - -print(x) - diff --git a/inst/doc/introduction.Rmd b/inst/doc/introduction.Rmd deleted file mode 100644 index ef48bde..0000000 --- a/inst/doc/introduction.Rmd +++ /dev/null @@ -1,182 +0,0 @@ ---- -title: "Introduction to nomisr" -author: "Evan Odell" -date: "`r Sys.Date()`" -output: - html_document: - toc: true - toc_float: true - theme: flatly -vignette: > - %\VignetteIndexEntry{Introduction to nomisr} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - -# Introduction to the Nomis API - -`nomisr` is for accessing [Nomis](https://www.nomisweb.co.uk/) data with R. The Nomis API is free to access without registration, and contains up-to-date official statistics, including data from the Census, the Labour Force Survey, DWP benefit statistics and other economic and demographic data. Nomis is maintained on behalf of the Office for National Statistics by the University of Durham. - -There is a lot of data available through Nomis, and there are some limits to the amount of data that can be retrieved within a certain period of time, although those are not published. For more details, see the [full API documentation](https://www.nomisweb.co.uk/api/v01/help) from Nomis. - -Nomis data is based around administrative and statistical geographies, and a particular geography should be specified when downloading data. - -`nomisr` is designed around a pipeline of three key functions: `nomis_data_info()`, `nomis_get_metadata()` and `nomis_get_data()`. The `nomis_overview()`, `nomis_content_type()` and `nomis_search()` functions can assist with this. - -## Querying data availability - -The `nomis_data_info()` function is focused on the structure and coverage of the available datasets. - -Use the `nomis_data_info()` function without any parameters to get a tibble with metadata for all available datasets: - -```{r, echo=TRUE} -library(nomisr) -x <- nomis_data_info() -head(x) -``` - - -`nomis_data_info()` can also be used to query metadata from a specific dataset, using its ID. The example below uses the "LC4408EW - Tenure by number of persons per bedroom in household by household type" dataset from the 2011 census, which has the ID "NM_893_1". - -```{r, echo=TRUE} -y <- nomis_data_info("NM_893_1") - -tibble::glimpse(y) -``` - -When a tibble with metadata for all datasets or a specific dataset is returned, three of the columns, `annotations.annotation`, `components.attribute` and `components.dimension`, are list-columns of data frames. `annotations.annotation` contains metadata on the dataset, including units and current status. `components.attribute` contains more detailed status metadata. `components.dimension` contains the grouping and summary variables available in the dataset, which vary between different datasets. - -The example below shows how to access data stored in list columns returned from the Nomis API. In the case of requests for metadata from a single dataset, the three columns are all lists with a length of 1. If requesting all dataset information with `nomis_data_info()`, each row is a list of length 1. Each list contains a data.frame, of varrying dimensions depending on the column and dataset. You can unnest individual list-columns to display their data in the same row as data from the rest of the tibble. Due to the differing lengths of the list-columns returned by `nomis_data_info()`, only one list-column can be unnested at a time. - -```{r, echo=TRUE} -library(dplyr, warn.conflicts = F) - -y$annotations.annotation %>% class() - -y$annotations.annotation %>% length() - -y$annotations.annotation[[1]] %>% class() - -y %>% pull(annotations.annotation) %>% class() - -y %>% pull(annotations.annotation) %>% .[[1]] %>% class() - -y %>% pull(annotations.annotation) %>% purrr::pluck() %>% class() - -## Unnesting list columns -y %>% tidyr::unnest(annotations.annotation) %>% glimpse() -``` - -### Searching for data - -`nomisr` also contains the `nomis_search()` function to search for datasets on particular topics. `nomis_search()` can be used to search in one or more of dataset names, descriptions, keywords, content type and units. If using multiple parameters, `nomis_search()` will return information on all datasets that match one or more parameters. Character vectors of strings can be used in searches, and likewise `nomis_search()` will return information on datasets that match one or more queries. The * is used as a wildcard symbol. `nomis_search()` returns metadata in the same format as `nomis_data_info()`, including using list-columns. The `nomis_content_type()` function can assist in identifying content type IDs for `nomis_search()`. - -```{r, echo=TRUE} -a <- nomis_search(name = '*jobseekers*', keywords = 'Claimants') - -tibble::glimpse(a) - -a %>% tidyr::unnest(components.attribute) %>% glimpse() - -b <- nomis_search(keywords = c('Claimants', '*Year*')) - -tibble::glimpse(b) - -b %>% tidyr::unnest(components.attribute) %>% glimpse() - -``` - - -### Other ways to access metadata - -`nomis_overview()` returns a tibble with a generalised overview of a given dataset. - - -```{r, echo=TRUE} -q <- nomis_overview("NM_1650_1") - -q %>% tidyr::unnest(name) %>% glimpse() - -``` - -`nomis_overview()` has a `select` parameter that can be used to select only particular elements of the overview to return. - -```{r, echo=TRUE} - s <- nomis_overview("NM_1650_1", select = c("units", "keywords")) - - s %>% tidyr::unnest(name) %>% glimpse() -``` - - -## Querying data variables - -Vast amounts of data are available through Nomis and so to avoid overwhelming the API, it is good practice to query what concepts are available, using `nomis_get_metadata()`. While the other metadata functions can return concept metadata, `nomis_get_metadata()` provides greater flexibility and specificity over the returned metadata than `nomis_overview()` and `nomis_data_info()`. - -The example below queries some of the metadata available through the API for the "LC4408EW - Tenure bynumber of persons per bedroom in household by household type" dataset. - -### Getting concepts - -If provided with just a dataset ID, `nomis_get_metadata()` will return the concepts available for the given dataset. - -```{r, echo=TRUE} - - a <- nomis_get_metadata(id = "NM_893_1") - - print(a) -``` - -### Concept Values - -If provided with a concept name it returns the available values for that concept. However, in some cases, espescially with the geography concept, there are multiple options available, which Nomis labels types. In that case `nomis_get_metadata()` returns the values of the lowest indexed type available. - -```{r, echo=TRUE} - b <- nomis_get_metadata(id = "NM_893_1", concept = "GEOGRAPHY") - - print(b) -``` - -We can now pass a generic "type" string to the `type` parameter in `nomis_get_metadata()`, which returns all available geography types for dataset "NM_893_1". - - -```{r, echo=TRUE} - c <- nomis_get_metadata(id = "NM_893_1", concept = "geography", type = "type") - - print(c) -``` - - -Passing a specific type to the `type` parameter, in this case "TYPE460" for all post-2010 parliamentary constituencies, returns a tibble with geographic codes for those specific constituencies, which can be used to filter queries. - -```{r, echo=TRUE} - d <- nomis_get_metadata(id = "NM_893_1", concept = "geography", type = "TYPE460") - - print(d) -``` - - -The vast majority (98% as of February 2018) of Nomis datasets include a geographic variable. - -## Downloading data - -Using the information above, we can now query the latest data on bedroom occupancy per household type in different NHS clinical commissioning groups. - -```{r, echo=TRUE} - z <- nomis_get_data(id = "NM_893_1", time = "latest", geography = "TYPE266") - -print(z) -``` - - -We can also query bedroom occupancy per household type in the Manchester, Gorton and Manchester, Withington parliamentary constituencies. - -```{r, echo=TRUE} - x <- nomis_get_data(id = "NM_893_1", time = "latest", geography = c("1929380119", "1929380120")) - -print(x) -``` - - - - - - diff --git a/inst/doc/introduction.html b/inst/doc/introduction.html deleted file mode 100644 index 54b8151..0000000 --- a/inst/doc/introduction.html +++ /dev/null @@ -1,570 +0,0 @@ - - - - - - - - - - - - - - - -Introduction to nomisr - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
-
-
-
-
- -
- - - - - - - -
-

Introduction to the Nomis API

-

nomisr is for accessing Nomis data with R. The Nomis API is free to access without registration, and contains up-to-date official statistics, including data from the Census, the Labour Force Survey, DWP benefit statistics and other economic and demographic data. Nomis is maintained on behalf of the Office for National Statistics by the University of Durham.

-

There is a lot of data available through Nomis, and there are some limits to the amount of data that can be retrieved within a certain period of time, although those are not published. For more details, see the full API documentation from Nomis.

-

Nomis data is based around administrative and statistical geographies, and a particular geography should be specified when downloading data.

-

nomisr is designed around a pipeline of three key functions: nomis_data_info(), nomis_get_metadata() and nomis_get_data(). The nomis_overview(), nomis_content_type() and nomis_search() functions can assist with this.

-
-

Querying data availability

-

The nomis_data_info() function is focused on the structure and coverage of the available datasets.

-

Use the nomis_data_info() function without any parameters to get a tibble with metadata for all available datasets:

-
library(nomisr)
-x <- nomis_data_info()
-head(x)
-
## # A tibble: 6 x 14
-##   agencyid id     uri    version annotations.annotati… components.attribu…
-##   <chr>    <chr>  <chr>    <dbl> <list>                <list>             
-## 1 NOMIS    NM_1_1 Nm-1d1    1.00 <data.frame [10 × 2]> <data.frame [7 × 4…
-## 2 NOMIS    NM_2_1 Nm-2d1    1.00 <data.frame [6 × 2]>  <data.frame [7 × 4…
-## 3 NOMIS    NM_4_1 Nm-4d1    1.00 <data.frame [8 × 2]>  <data.frame [7 × 4…
-## 4 NOMIS    NM_5_1 Nm-5d1    1.00 <data.frame [5 × 2]>  <data.frame [7 × 4…
-## 5 NOMIS    NM_6_1 Nm-6d1    1.00 <data.frame [6 × 2]>  <data.frame [7 × 4…
-## 6 NOMIS    NM_7_1 Nm-7d1    1.00 <data.frame [6 × 2]>  <data.frame [7 × 4…
-## # ... with 8 more variables: components.dimension <list>,
-## #   components.primarymeasure.conceptref <chr>,
-## #   components.timedimension.codelist <chr>,
-## #   components.timedimension.conceptref <chr>, description.value <chr>,
-## #   description.lang <chr>, name.value <chr>, name.lang <chr>
-

nomis_data_info() can also be used to query metadata from a specific dataset, using its ID. The example below uses the “LC4408EW - Tenure by number of persons per bedroom in household by household type” dataset from the 2011 census, which has the ID “NM_893_1”.

-
y <- nomis_data_info("NM_893_1")
-
-tibble::glimpse(y)
-
## Observations: 1
-## Variables: 12
-## $ agencyid                             <chr> "NOMIS"
-## $ id                                   <chr> "NM_893_1"
-## $ uri                                  <chr> "Nm-893d1"
-## $ version                              <dbl> 1
-## $ annotations.annotation               <list> [<c("Current (being acti...
-## $ components.attribute                 <list> [<c("Mandatory", "Condit...
-## $ components.dimension                 <list> [<c("CL_893_1_GEOGRAPHY"...
-## $ components.primarymeasure.conceptref <chr> "OBS_VALUE"
-## $ components.timedimension.codelist    <chr> "CL_893_1_TIME"
-## $ components.timedimension.conceptref  <chr> "TIME"
-## $ name.value                           <chr> "LC4408EW - Tenure by num...
-## $ name.lang                            <chr> "en"
-

When a tibble with metadata for all datasets or a specific dataset is returned, three of the columns, annotations.annotation, components.attribute and components.dimension, are list-columns of data frames. annotations.annotation contains metadata on the dataset, including units and current status. components.attribute contains more detailed status metadata. components.dimension contains the grouping and summary variables available in the dataset, which vary between different datasets.

-

The example below shows how to access data stored in list columns returned from the Nomis API. In the case of requests for metadata from a single dataset, the three columns are all lists with a length of 1. If requesting all dataset information with nomis_data_info(), each row is a list of length 1. Each list contains a data.frame, of varrying dimensions depending on the column and dataset. You can unnest individual list-columns to display their data in the same row as data from the rest of the tibble. Due to the differing lengths of the list-columns returned by nomis_data_info(), only one list-column can be unnested at a time.

-
library(dplyr, warn.conflicts = F)
-
-y$annotations.annotation %>% class()
-
## [1] "list"
-
y$annotations.annotation %>% length()
-
## [1] 1
-
y$annotations.annotation[[1]] %>% class()
-
## [1] "data.frame"
-
y %>% pull(annotations.annotation) %>% class()
-
## [1] "list"
-
y %>% pull(annotations.annotation) %>% .[[1]] %>% class()
-
## [1] "data.frame"
-
y %>% pull(annotations.annotation) %>% purrr::pluck() %>% class()
-
## [1] "list"
-
## Unnesting list columns
-y %>% tidyr::unnest(annotations.annotation) %>% glimpse()
-
## Observations: 14
-## Variables: 11
-## $ agencyid                             <chr> "NOMIS", "NOMIS", "NOMIS"...
-## $ id                                   <chr> "NM_893_1", "NM_893_1", "...
-## $ uri                                  <chr> "Nm-893d1", "Nm-893d1", "...
-## $ version                              <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1...
-## $ components.primarymeasure.conceptref <chr> "OBS_VALUE", "OBS_VALUE",...
-## $ components.timedimension.codelist    <chr> "CL_893_1_TIME", "CL_893_...
-## $ components.timedimension.conceptref  <chr> "TIME", "TIME", "TIME", "...
-## $ name.value                           <chr> "LC4408EW - Tenure by num...
-## $ name.lang                            <chr> "en", "en", "en", "en", "...
-## $ annotationtext                       <chr> "Current (being actively ...
-## $ annotationtitle                      <chr> "Status", "Keywords", "Un...
-
-

Searching for data

-

nomisr also contains the nomis_search() function to search for datasets on particular topics. nomis_search() can be used to search in one or more of dataset names, descriptions, keywords, content type and units. If using multiple parameters, nomis_search() will return information on all datasets that match one or more parameters. Character vectors of strings can be used in searches, and likewise nomis_search() will return information on datasets that match one or more queries. The * is used as a wildcard symbol. nomis_search() returns metadata in the same format as nomis_data_info(), including using list-columns. The nomis_content_type() function can assist in identifying content type IDs for nomis_search().

-
a <- nomis_search(name = '*jobseekers*', keywords = 'Claimants')
-
-tibble::glimpse(a)
-
## Observations: 33
-## Variables: 14
-## $ agencyid                             <chr> "NOMIS", "NOMIS", "NOMIS"...
-## $ id                                   <chr> "NM_1_1", "NM_2_1", "NM_6...
-## $ uri                                  <chr> "Nm-1d1", "Nm-2d1", "Nm-6...
-## $ version                              <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1...
-## $ annotations.annotation               <list> [<c("Current (being acti...
-## $ components.attribute                 <list> [<c("Mandatory", "Condit...
-## $ components.dimension                 <list> [<c("CL_1_1_GEOGRAPHY", ...
-## $ components.primarymeasure.conceptref <chr> "OBS_VALUE", "OBS_VALUE",...
-## $ components.timedimension.codelist    <chr> "CL_1_1_TIME", "CL_2_1_TI...
-## $ components.timedimension.conceptref  <chr> "TIME", "TIME", "TIME", "...
-## $ description.value                    <chr> "Records the number of pe...
-## $ description.lang                     <chr> "en", "en", "en", "en", N...
-## $ name.value                           <chr> "Jobseeker's Allowance wi...
-## $ name.lang                            <chr> "en", "en", "en", "en", "...
-
a %>% tidyr::unnest(components.attribute) %>% glimpse()
-
## Observations: 231
-## Variables: 15
-## $ agencyid                             <chr> "NOMIS", "NOMIS", "NOMIS"...
-## $ id                                   <chr> "NM_1_1", "NM_1_1", "NM_1...
-## $ uri                                  <chr> "Nm-1d1", "Nm-1d1", "Nm-1...
-## $ version                              <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1...
-## $ components.primarymeasure.conceptref <chr> "OBS_VALUE", "OBS_VALUE",...
-## $ components.timedimension.codelist    <chr> "CL_1_1_TIME", "CL_1_1_TI...
-## $ components.timedimension.conceptref  <chr> "TIME", "TIME", "TIME", "...
-## $ description.value                    <chr> "Records the number of pe...
-## $ description.lang                     <chr> "en", "en", "en", "en", "...
-## $ name.value                           <chr> "Jobseeker's Allowance wi...
-## $ name.lang                            <chr> "en", "en", "en", "en", "...
-## $ assignmentstatus                     <chr> "Mandatory", "Conditional...
-## $ attachmentlevel                      <chr> "Observation", "Observati...
-## $ codelist                             <chr> "CL_OBS_STATUS", "CL_OBS_...
-## $ conceptref                           <chr> "OBS_STATUS", "OBS_CONF",...
-
b <- nomis_search(keywords = c('Claimants', '*Year*'))
-
-tibble::glimpse(b)
-
## Observations: 82
-## Variables: 14
-## $ agencyid                             <chr> "NOMIS", "NOMIS", "NOMIS"...
-## $ id                                   <chr> "NM_1_1", "NM_2_1", "NM_5...
-## $ uri                                  <chr> "Nm-1d1", "Nm-2d1", "Nm-5...
-## $ version                              <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1...
-## $ annotations.annotation               <list> [<c("Current (being acti...
-## $ components.attribute                 <list> [<c("Mandatory", "Condit...
-## $ components.dimension                 <list> [<c("CL_1_1_GEOGRAPHY", ...
-## $ components.primarymeasure.conceptref <chr> "OBS_VALUE", "OBS_VALUE",...
-## $ components.timedimension.codelist    <chr> "CL_1_1_TIME", "CL_2_1_TI...
-## $ components.timedimension.conceptref  <chr> "TIME", "TIME", "TIME", "...
-## $ description.value                    <chr> "Records the number of pe...
-## $ description.lang                     <chr> "en", "en", "en", "en", "...
-## $ name.value                           <chr> "Jobseeker's Allowance wi...
-## $ name.lang                            <chr> "en", "en", "en", "en", "...
-
b %>% tidyr::unnest(components.attribute) %>% glimpse()
-
## Observations: 574
-## Variables: 15
-## $ agencyid                             <chr> "NOMIS", "NOMIS", "NOMIS"...
-## $ id                                   <chr> "NM_1_1", "NM_1_1", "NM_1...
-## $ uri                                  <chr> "Nm-1d1", "Nm-1d1", "Nm-1...
-## $ version                              <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1...
-## $ components.primarymeasure.conceptref <chr> "OBS_VALUE", "OBS_VALUE",...
-## $ components.timedimension.codelist    <chr> "CL_1_1_TIME", "CL_1_1_TI...
-## $ components.timedimension.conceptref  <chr> "TIME", "TIME", "TIME", "...
-## $ description.value                    <chr> "Records the number of pe...
-## $ description.lang                     <chr> "en", "en", "en", "en", "...
-## $ name.value                           <chr> "Jobseeker's Allowance wi...
-## $ name.lang                            <chr> "en", "en", "en", "en", "...
-## $ assignmentstatus                     <chr> "Mandatory", "Conditional...
-## $ attachmentlevel                      <chr> "Observation", "Observati...
-## $ codelist                             <chr> "CL_OBS_STATUS", "CL_OBS_...
-## $ conceptref                           <chr> "OBS_STATUS", "OBS_CONF",...
-
-
-

Other ways to access metadata

-

nomis_overview() returns a tibble with a generalised overview of a given dataset.

-
q <- nomis_overview("NM_1650_1")
-
-q %>% tidyr::unnest(name) %>% glimpse()
-
## Observations: 20
-## Variables: 2
-## $ value <list> [[<c("1", "4", "5"), c("NM_1650_1", "NM_1650_4", "NM_16...
-## $ name  <chr> "analyses", "analysisname", "analysisnumber", "contact",...
-

nomis_overview() has a select parameter that can be used to select only particular elements of the overview to return.

-
 s <- nomis_overview("NM_1650_1", select = c("units", "keywords"))
- 
- s %>% tidyr::unnest(name) %>% glimpse()
-
## Observations: 3
-## Variables: 2
-## $ value <list> ["NM_1650_1", "Year last worked", [["Persons"]]]
-## $ name  <chr> "id", "keywords", "units"
-
-
-
-

Querying data variables

-

Vast amounts of data are available through Nomis and so to avoid overwhelming the API, it is good practice to query what concepts are available, using nomis_get_metadata(). While the other metadata functions can return concept metadata, nomis_get_metadata() provides greater flexibility and specificity over the returned metadata than nomis_overview() and nomis_data_info().

-

The example below queries some of the metadata available through the API for the “LC4408EW - Tenure bynumber of persons per bedroom in household by household type” dataset.

-
-

Getting concepts

-

If provided with just a dataset ID, nomis_get_metadata() will return the concepts available for the given dataset.

-
  a <- nomis_get_metadata(id = "NM_893_1")
-
-  print(a)
-
## # A tibble: 6 x 3
-##   codelist                conceptref     isfrequencydimension
-## * <chr>                   <chr>          <chr>               
-## 1 CL_893_1_GEOGRAPHY      GEOGRAPHY      false               
-## 2 CL_893_1_C_TENHUK11     C_TENHUK11     false               
-## 3 CL_893_1_C_PPBROOMHEW11 C_PPBROOMHEW11 false               
-## 4 CL_893_1_C_AHTHUK11     C_AHTHUK11     false               
-## 5 CL_893_1_MEASURES       MEASURES       false               
-## 6 CL_893_1_FREQ           FREQ           true
-
-
-

Concept Values

-

If provided with a concept name it returns the available values for that concept. However, in some cases, espescially with the geography concept, there are multiple options available, which Nomis labels types. In that case nomis_get_metadata() returns the values of the lowest indexed type available.

-
  b <- nomis_get_metadata(id = "NM_893_1", concept = "GEOGRAPHY")
-
-  print(b)
-
## # A tibble: 3 x 2
-##   description            value
-##   <chr>                  <int>
-## 1 England and Wales 2092957703
-## 2 England           2092957699
-## 3 Wales             2092957700
-

We can now pass a generic “type” string to the type parameter in nomis_get_metadata(), which returns all available geography types for dataset “NM_893_1”.

-
  c <- nomis_get_metadata(id = "NM_893_1", concept = "geography", type = "type")
-
-  print(c)
-
## # A tibble: 22 x 2
-##    description                                        value  
-##    <chr>                                              <chr>  
-##  1 NHS area teams                                     TYPE265
-##  2 clinical commissioning groups                      TYPE266
-##  3 built-up areas including subdivisions              TYPE267
-##  4 built-up areas                                     TYPE269
-##  5 national assembly for wales electoral regions 2010 TYPE273
-##  6 postcode areas                                     TYPE274
-##  7 postcode districts                                 TYPE275
-##  8 postcode sectors                                   TYPE276
-##  9 national assembly for wales constituencies 2010    TYPE277
-## 10 parishes 2011                                      TYPE279
-## # ... with 12 more rows
-

Passing a specific type to the type parameter, in this case “TYPE460” for all post-2010 parliamentary constituencies, returns a tibble with geographic codes for those specific constituencies, which can be used to filter queries.

-
  d <- nomis_get_metadata(id = "NM_893_1", concept = "geography", type = "TYPE460")
-
-  print(d)
-
## # A tibble: 573 x 2
-##    description             value
-##    <chr>                   <int>
-##  1 Berwick-upon-Tweed 1929379865
-##  2 Bishop Auckland    1929379880
-##  3 Blaydon            1929379885
-##  4 Blyth Valley       1929379886
-##  5 City of Durham     1929379952
-##  6 Darlington         1929379969
-##  7 Easington          1929379988
-##  8 Gateshead          1929380020
-##  9 Hartlepool         1929380044
-## 10 Hexham             1929380057
-## # ... with 563 more rows
-

The vast majority (98% as of February 2018) of Nomis datasets include a geographic variable.

-
-
-
-

Downloading data

-

Using the information above, we can now query the latest data on bedroom occupancy per household type in different NHS clinical commissioning groups.

-
 z <- nomis_get_data(id = "NM_893_1", time = "latest", geography = "TYPE266")
-
## Retrieving additional pages 1 of 1
-
print(z)
-
## # A tibble: 44,310 x 40
-##    DATE  DATE_NAME DATE_CODE DATE_TYPE DATE_TYPECODE DATE_SORTORDER
-##    <chr> <chr>     <chr>     <chr>     <chr>         <chr>         
-##  1 2011  2011      2011      date      0             0             
-##  2 2011  2011      2011      date      0             0             
-##  3 2011  2011      2011      date      0             0             
-##  4 2011  2011      2011      date      0             0             
-##  5 2011  2011      2011      date      0             0             
-##  6 2011  2011      2011      date      0             0             
-##  7 2011  2011      2011      date      0             0             
-##  8 2011  2011      2011      date      0             0             
-##  9 2011  2011      2011      date      0             0             
-## 10 2011  2011      2011      date      0             0             
-## # ... with 44,300 more rows, and 34 more variables: GEOGRAPHY <chr>,
-## #   GEOGRAPHY_NAME <chr>, GEOGRAPHY_CODE <chr>, GEOGRAPHY_TYPE <chr>,
-## #   GEOGRAPHY_TYPECODE <chr>, GEOGRAPHY_SORTORDER <chr>, C_TENHUK11 <chr>,
-## #   C_TENHUK11_NAME <chr>, C_TENHUK11_CODE <chr>, C_TENHUK11_TYPE <chr>,
-## #   C_TENHUK11_TYPECODE <chr>, C_TENHUK11_SORTORDER <chr>,
-## #   C_PPBROOMHEW11 <chr>, C_PPBROOMHEW11_NAME <chr>,
-## #   C_PPBROOMHEW11_CODE <chr>, C_PPBROOMHEW11_TYPE <chr>,
-## #   C_PPBROOMHEW11_TYPECODE <chr>, C_PPBROOMHEW11_SORTORDER <chr>,
-## #   C_AHTHUK11 <chr>, C_AHTHUK11_NAME <chr>, C_AHTHUK11_CODE <chr>,
-## #   C_AHTHUK11_TYPE <chr>, C_AHTHUK11_TYPECODE <chr>,
-## #   C_AHTHUK11_SORTORDER <chr>, MEASURES <chr>, MEASURES_NAME <chr>,
-## #   OBS_VALUE <chr>, OBS_STATUS <chr>, OBS_STATUS_NAME <chr>,
-## #   OBS_CONF <chr>, OBS_CONF_NAME <chr>, URN <chr>, RECORD_OFFSET <chr>,
-## #   RECORD_COUNT <chr>
-

We can also query bedroom occupancy per household type in the Manchester, Gorton and Manchester, Withington parliamentary constituencies.

-
 x <- nomis_get_data(id = "NM_893_1", time = "latest", geography = c("1929380119", "1929380120"))
- 
-print(x)
-
## # A tibble: 420 x 40
-##    DATE  DATE_NAME DATE_CODE DATE_TYPE DATE_TYPECODE DATE_SORTORDER
-##    <chr> <chr>     <chr>     <chr>     <chr>         <chr>         
-##  1 2011  2011      2011      date      0             0             
-##  2 2011  2011      2011      date      0             0             
-##  3 2011  2011      2011      date      0             0             
-##  4 2011  2011      2011      date      0             0             
-##  5 2011  2011      2011      date      0             0             
-##  6 2011  2011      2011      date      0             0             
-##  7 2011  2011      2011      date      0             0             
-##  8 2011  2011      2011      date      0             0             
-##  9 2011  2011      2011      date      0             0             
-## 10 2011  2011      2011      date      0             0             
-## # ... with 410 more rows, and 34 more variables: GEOGRAPHY <chr>,
-## #   GEOGRAPHY_NAME <chr>, GEOGRAPHY_CODE <chr>, GEOGRAPHY_TYPE <chr>,
-## #   GEOGRAPHY_TYPECODE <chr>, GEOGRAPHY_SORTORDER <chr>, C_TENHUK11 <chr>,
-## #   C_TENHUK11_NAME <chr>, C_TENHUK11_CODE <chr>, C_TENHUK11_TYPE <chr>,
-## #   C_TENHUK11_TYPECODE <chr>, C_TENHUK11_SORTORDER <chr>,
-## #   C_PPBROOMHEW11 <chr>, C_PPBROOMHEW11_NAME <chr>,
-## #   C_PPBROOMHEW11_CODE <chr>, C_PPBROOMHEW11_TYPE <chr>,
-## #   C_PPBROOMHEW11_TYPECODE <chr>, C_PPBROOMHEW11_SORTORDER <chr>,
-## #   C_AHTHUK11 <chr>, C_AHTHUK11_NAME <chr>, C_AHTHUK11_CODE <chr>,
-## #   C_AHTHUK11_TYPE <chr>, C_AHTHUK11_TYPECODE <chr>,
-## #   C_AHTHUK11_SORTORDER <chr>, MEASURES <chr>, MEASURES_NAME <chr>,
-## #   OBS_VALUE <chr>, OBS_STATUS <chr>, OBS_STATUS_NAME <chr>,
-## #   OBS_CONF <chr>, OBS_CONF_NAME <chr>, URN <chr>, RECORD_OFFSET <chr>,
-## #   RECORD_COUNT <chr>
-
-
- - - -
-
- -
- - - - - - - - diff --git a/tests/testthat/test_get_data.R b/tests/testthat/test_get_data.R index 5505939..af139f8 100644 --- a/tests/testthat/test_get_data.R +++ b/tests/testthat/test_get_data.R @@ -97,7 +97,6 @@ test_that("nomis_get_data return expected format", { geography = "TYPE464", sex = 0, cause_of_death = "10381", age = 0, measure = 6 - ), - "The API request did not return any results.\nPlease check your parameters." + ) ) })