nomis_get_data {nomisr} | R Documentation |
Retrieve Nomis datasets
Description
To find the code options for a given dataset, use
nomis_get_metadata()
for specific codes, and
nomis_codelist()
for code values.
This can be a slow process if querying significant amounts of
data. Guest users are limited to 25,000 rows per query, although
nomisr
identifies queries that will return more than 25,000 rows,
sending individual queries and combining the results of those queries into
a single tibble. In interactive sessions, nomisr
will warn you if
guest users are requesting more than 350,000 rows of data, and if
registered users are requesting more than 1,500,000 rows.
Note the difference between the time
and date
parameters. The time
and date
parameters should not be used at the same
time. If they are, the function will retrieve data based on the the
date
parameter. If given more than one query, time
will
return all data available between those queries, inclusively, while
date
will only return data for the exact queries specified. So
time = c("first", "latest")
will return all data, while
date = c("first", "latest")
will return only the earliest and latest
data published.
Usage
nomis_get_data(
id,
time = NULL,
date = NULL,
geography = NULL,
sex = NULL,
measures = NULL,
additional_queries = NULL,
exclude_missing = FALSE,
select = NULL,
tidy = FALSE,
tidy_style = "snake_case",
query_id = NULL,
...
)
Arguments
id |
A string containing the ID of the dataset to retrieve,
in |
time |
Parameter for selecting dates and date ranges. Accepts either a single date value, or two date values and returns all data between the two date values, There are two styles of values that can be used to query time. The first is one or two of The second style is to use or a specific date or multiple dates, in the
style of the time variable codelist, which can be found using the
Values for the Defaults to |
date |
Parameter for selecting specific dates. Accepts one or more date
values. If given multiple values, only data for the given dates will be
returned, but there is no limit to the number of data values. For example,
The first is one or more of The second style is to use or a specific date or multiple dates, in the
style of the time variable codelist, which can be found using the
Values for the Defaults to |
geography |
The code of the geographic area to return data for. If
|
sex |
The code for sexes/genders to include in the dataset.
Accepts a string or number, or a vector of strings or numbers.
There are two different codings used for sex, depending on the dataset. For
datasets using |
measures |
The code for the statistical measure(s) to include in the
data. Accepts a single string or number, or a list of strings or numbers.
If |
additional_queries |
Any other additional queries to pass to the API.
See https://www.nomisweb.co.uk/api/v01/help for instructions on
query structure. Defaults to |
exclude_missing |
If |
select |
A character vector of one or more variables to include in
the returned data, excluding all others. |
tidy |
Logical parameter. If |
tidy_style |
The style to convert variable names to, if
|
query_id |
Results can be labelled as belonging to a certain query
made to the API. |
... |
Use to pass any other parameters to the API. Useful for passing
concepts that are not available through the default parameters. Only accepts
concepts identified in |
Value
A tibble containing the selected dataset. By default, all tibble
columns except for the "OBS_VALUE"
column are parsed as characters.
See Also
Examples
# Return data on Jobseekers Allowance for each country in the UK
jobseekers_country <- nomis_get_data(
id = "NM_1_1", time = "latest",
geography = "TYPE499",
measures = c(20100, 20201), sex = 5
)
# Return data on Jobseekers Allowance for Wigan
jobseekers_wigan <- nomis_get_data(
id = "NM_1_1", time = "latest",
geography = "1879048226",
measures = c(20100, 20201), sex = "5"
)
# annual population survey - regional - employment by occupation
emp_by_occupation <- nomis_get_data(
id = "NM_168_1", time = "latest",
geography = "2013265925", sex = "0",
select = c(
"geography_code",
"C_OCCPUK11H_0_NAME", "obs_vAlUE"
)
)
# Deaths in 2016 and 2015 by three specified causes,
# identified with nomis_get_metadata()
death <- nomis_get_data("NM_161_1",
date = c("2016", "2015"),
geography = "TYPE480",
cause_of_death = c(10300, 102088, 270)
)
# All causes of death in London in 2016
london_death <- nomis_get_data("NM_161_1",
date = c("2016"),
geography = "2013265927", sex = 1, age = 0
)
## Not run:
# Results in an error because `measure` is mistaken for `measures`
mort_data1 <- nomis_get_data(
id = "NM_161_1", date = "2016",
geography = "TYPE464", sex = 0, cause_of_death = "10381",
age = 0, measure = 6
)
# Does not error because `measures` is specified
mort_data2 <- nomis_get_data(
id = "NM_161_1", date = "2016",
geography = "TYPE464", sex = 0, measures = NULL,
cause_of_death = "10381", age = 0, measure = 6
)
## End(Not run)