Skip to content

Commit

Permalink
new roxygen version, code tidying [ci-skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
evanodell committed Feb 2, 2020
1 parent 3c80c6a commit 9680ca6
Show file tree
Hide file tree
Showing 19 changed files with 232 additions and 154 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Imports:
utils,
rsdmx,
rlang
RoxygenNote: 6.1.1
RoxygenNote: 7.0.2
Suggests:
knitr,
rmarkdown,
Expand Down
2 changes: 1 addition & 1 deletion R/api-key.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' reload the API key or would like to manually enter one in, this function
#' may be used.
#'
#' @details You can sign up for an API key
#' @details You can sign up for an API key
#' [here](https://www.nomisweb.co.uk/myaccount/userjoin.asp).
#'
#' @param check_env If TRUE, will check the environment variable
Expand Down
5 changes: 3 additions & 2 deletions R/codelist.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
#' @seealso [nomis_get_metadata()]
#' @seealso [nomis_overview()]
#'
#' @examples \donttest{
#' @examples
#' \donttest{
#' x <- nomis_codelist("NM_1_1", "item")
#'
#'
Expand All @@ -34,7 +35,7 @@
#'
#' z <- nomis_codelist("NM_161_1", "cause_of_death")
#' }

#'
nomis_codelist <- function(id, concept, search = NULL) {
if (missing(id)) {
stop("id must be specified", call. = FALSE)
Expand Down
6 changes: 3 additions & 3 deletions R/content_type.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#' @seealso [nomis_search()]
#' @seealso [nomis_data_info()]
#'
#' @examples \donttest{
#' @examples
#' \donttest{
#' a <- nomis_content_type("sources")
#'
#' tibble::glimpse(a)
Expand All @@ -27,8 +28,7 @@
#'
#' tibble::glimpse(b)
#' }


#'
nomis_content_type <- function(content_type, id = NULL) {
if (missing(content_type)) {
stop("content_type must be specified", call. = FALSE)
Expand Down
109 changes: 63 additions & 46 deletions R/data_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
#' `date = c("first", "latest")` will return only the earliest and latest
#' data published.
#'
#' @param id A string containing the ID of the dataset to retrieve,
#' @param id A string containing the ID of the dataset to retrieve,
#' in `"nm_***_*"` format. The `id` parameter is not case sensitive.
#'
#' @param 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 `"latest"` (returns the latest available
#' data), `"previous"` (the date prior to `"latest"`), `"prevyear"`
#' (the date one year prior to `"latest"`) or `"first"`
#' data), `"previous"` (the date prior to `"latest"`), `"prevyear"`
#' (the date one year prior to `"latest"`) or `"first"`
#' (the oldest available data for the dataset).
#'
#' The second style is to use or a specific date or multiple dates, in the
Expand All @@ -56,7 +56,7 @@
#' returned, but there is no limit to the number of data values. For example,
#' `date=c("latest, latestMINUS3, latestMINUS6")` will return the latest
#' data, data from three months prior to the latest data and six months prior
#' to the latest data. There are two styles of values that can be used to
#' to the latest data. There are two styles of values that can be used to
#' query time.
#'
#' The first is one or more of `"latest"` (returns the latest available
Expand Down Expand Up @@ -92,17 +92,17 @@
#' all available sex/gender data.
#'
#' There are two different codings used for sex, depending on the dataset. For
#' datasets using `"SEX"`, `7` will return results for males and females, `6`
#' only females and `5` only males. Defaults to `NULL`, equivalent to
#' `c(5,6,7)` for datasets where sex is an option. For datasets using
#' `"C_SEX"`, `0` will return results for males and females, `1` only males
#' and `2` only females. Some datasets use `"GENDER"` with the same values
#' as `"SEX"`, which works with both `sex = <code>` and `gender = <code>`
#' datasets using `"SEX"`, `7` will return results for males and females, `6`
#' only females and `5` only males. Defaults to `NULL`, equivalent to
#' `c(5,6,7)` for datasets where sex is an option. For datasets using
#' `"C_SEX"`, `0` will return results for males and females, `1` only males
#' and `2` only females. Some datasets use `"GENDER"` with the same values
#' as `"SEX"`, which works with both `sex = <code>` and `gender = <code>`
#' as a dot parameter.
#'
#' @param additional_queries Any other additional queries to pass to the API.
#' See \url{https://www.nomisweb.co.uk/api/v01/help} for instructions on
#' query structure. Defaults to `NULL`. Deprecated in package versions greater
#' query structure. Defaults to `NULL`. Deprecated in package versions greater
#' than 0.2.0 and will eventually be removed in a future version.
#'
#' @param exclude_missing If `TRUE`, excludes all missing values.
Expand All @@ -119,11 +119,11 @@
#' @param tidy_style The style to convert variable names to, if
#' `tidy = TRUE`. Accepts one of `"snake_case"`, `"camelCase"`
#' and `"period.case"`. Defaults to `"snake_case"`.
#'
#' @param query_id Results can be labelled as belonging to a certain query
#' made to the API. `query_id` accepts any value as a string, and will
#' be included in every row of the tibble returned by `nomis_get_data`
#' in a column labelled "QUERY_ID" in the default SCREAMING_SNAKE_CASE
#'
#' @param query_id Results can be labelled as belonging to a certain query
#' made to the API. `query_id` accepts any value as a string, and will
#' be included in every row of the tibble returned by `nomis_get_data`
#' in a column labelled "QUERY_ID" in the default SCREAMING_SNAKE_CASE
#' used by the API. Defaults to `NULL`.
#'
#' @param ... Use to pass any other parameters to the API. Useful for passing
Expand All @@ -135,66 +135,83 @@
#' Parameters are not case sensitive. Note that R using partial matching for
#' function variables, and so passing a parameter with the same opening
#' characters as one of the above-named parameters can cause an error unless
#' the value of the named parameter is specified, including as `NULL`.
#' the value of the named parameter is specified, including as `NULL`.
#' See example below:
#'
#' @return A tibble containing the selected dataset. By default, all tibble
#' @return A tibble containing the selected dataset. By default, all tibble
#' columns except for the `"OBS_VALUE"` column are parsed as characters.
#' @export
#' @seealso [nomis_data_info()]
#' @seealso [nomis_get_metadata()]
#' @seealso [nomis_codelist()]
#' @seealso [nomis_overview()]
#' @examples \donttest{
#' @examples
#' \donttest{
#'
#' # 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)
#' jobseekers_country <- nomis_get_data(
#' id = "NM_1_1", time = "latest",
#' geography = "TYPE499",
#' measures = c(20100, 20201), sex = 5
#' )
#'
#' tibble::glimpse(jobseekers_country)
#'
#' # 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")
#' jobseekers_wigan <- nomis_get_data(
#' id = "NM_1_1", time = "latest",
#' geography = "1879048226",
#' measures = c(20100, 20201), sex = "5"
#' )
#'
#' tibble::glimpse(jobseekers_wigan)
#'
#' # 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"))
#' 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"
#' )
#' )
#'
#' tibble::glimpse(emp_by_occupation)
#'
#' # Deaths in 2016 and 2015 by three specified causes,
#' # 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))
#' death <- nomis_get_data("NM_161_1",
#' date = c("2016", "2015"),
#' geography = "TYPE480",
#' cause_of_death = c(10300, 102088, 270)
#' )
#'
#' tibble::glimpse(death)
#'
#' # 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)
#' london_death <- nomis_get_data("NM_161_1",
#' date = c("2016"),
#' geography = "2013265927", sex = 1, age = 0
#' )
#'
#' tibble::glimpse(london_death)
#' }
#' \dontrun{
#' # 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)
#' # 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
#' )
#' }

#'
nomis_get_data <- function(id, time = NULL, date = NULL, geography = NULL,
sex = NULL, measures = NULL,
additional_queries = NULL, exclude_missing = FALSE,
Expand Down Expand Up @@ -270,7 +287,7 @@ nomis_get_data <- function(id, time = NULL, date = NULL, geography = NULL,
),
""
)

query_id <- ifelse(!is.null(query_id), paste0("&queryid=", query_id), "")

dots <- rlang::list2(...) ## eval the dots
Expand Down
8 changes: 4 additions & 4 deletions R/dataset_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
#' @seealso [nomis_overview()]
#' @seealso [nomis_codelist()]
#'
#' @examples \donttest{
#' @examples
#' \donttest{
#'
#' # Get info on all datasets
#' x <- nomis_data_info()
#'
#' tibble::glimpse(x)
#'
#' # Get info on a particular dataset
#' y <- nomis_data_info('NM_1658_1')
#' y <- nomis_data_info("NM_1658_1")
#'
#' tibble::glimpse(y)
#'
#' }

#'
nomis_data_info <- function(id) {
if (missing(id)) {
data_info_query <- "def.sdmx.json"
Expand Down
17 changes: 9 additions & 8 deletions R/metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,35 @@
#' [nomis_get_data()].
#' @export
#'
#' @examples \donttest{
#' a <- nomis_get_metadata('NM_1_1')
#' @examples
#' \donttest{
#' a <- nomis_get_metadata("NM_1_1")
#'
#' tibble::glimpse(a)
#'
#' b <- nomis_get_metadata('NM_1_1', 'geography')
#' b <- nomis_get_metadata("NM_1_1", "geography")
#'
#' tibble::glimpse(b)
#'
#' # returns all types of geography
#' c <- nomis_get_metadata('NM_1_1', 'geography', 'TYPE')
#' c <- nomis_get_metadata("NM_1_1", "geography", "TYPE")
#'
#' tibble::glimpse(c)
#'
#' # returns geography types available within Wigan
#' d <- nomis_get_metadata('NM_1_1', 'geography', '1879048226')
#' d <- nomis_get_metadata("NM_1_1", "geography", "1879048226")
#'
#' tibble::glimpse(d)
#'
#' e <- nomis_get_metadata('NM_1_1', 'item', geography = 1879048226, sex = 5)
#' e <- nomis_get_metadata("NM_1_1", "item", geography = 1879048226, sex = 5)
#'
#' print(e)
#'
#' f <- nomis_get_metadata('NM_1_1', 'item', search = "*married*")
#' f <- nomis_get_metadata("NM_1_1", "item", search = "*married*")
#'
#' tibble::glimpse(f)
#' }

#'
nomis_get_metadata <- function(id, concept = NULL,
type = NULL, search = NULL,
additional_queries = NULL, ...) {
Expand Down
14 changes: 9 additions & 5 deletions R/overview.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,23 @@
#' @seealso [nomis_data_info()]
#' @seealso [nomis_get_metadata()]
#'
#' @examples \donttest{
#' @examples
#' \donttest{
#' library(dplyr)
#'
#' q <- nomis_overview("NM_1650_1")
#'
#' q %>% tidyr::unnest(name) %>% glimpse()
#' q %>%
#' tidyr::unnest(name) %>%
#' glimpse()
#'
#' s <- nomis_overview("NM_1650_1", select = c("Units", "Keywords"))
#'
#' s %>% tidyr::unnest(name) %>% glimpse()
#' s %>%
#' tidyr::unnest(name) %>%
#' glimpse()
#' }


#'
nomis_overview <- function(id, select = NULL) {
if (missing(id)) {
stop("The dataset ID must be specified.", call. = FALSE)
Expand Down
10 changes: 5 additions & 5 deletions R/search.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
#' @export
#' @seealso [nomis_content_type()]
#'
#' @examples \donttest{
#' x <- nomis_search(name = '*seekers*')
#' @examples
#' \donttest{
#' x <- nomis_search(name = "*seekers*")
#'
#' y <- nomis_search(keywords = 'Claimants')
#' y <- nomis_search(keywords = "Claimants")
#'
#' # Return metadata of all datasets with content_type "sources".
#' a <- nomis_search(content_type = "sources")
Expand All @@ -42,8 +43,7 @@
#' # source ID "acses"
#' b <- nomis_search(content_type = "sources-acses")
#' }


#'
nomis_search <- function(name = NULL, description = NULL,
keywords = NULL, content_type = NULL, units = NULL) {
if (length(name) > 0) {
Expand Down
Loading

0 comments on commit 9680ca6

Please sign in to comment.