diff --git a/DESCRIPTION b/DESCRIPTION index ff764c6..4788e9c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,5 +22,6 @@ Imports: jsonlite, dplyr, stringr, - rlang, - magrittr + data.table, + magrittr, + rlang diff --git a/NAMESPACE b/NAMESPACE index 2422fce..3843fe0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,7 @@ export(api_url) export(api_url_pages) export(api_url_query) export(convert_api_filter_type) +export(example_data_raw) export(example_geography_query) export(example_id) export(example_json_query) @@ -18,6 +19,9 @@ export(parse_meta_filter_columns) export(parse_meta_filter_item_ids) export(parse_meta_location_ids) export(parse_meta_time_periods) +export(parse_sqids_filters) +export(parse_sqids_indicators) +export(parse_sqids_locations) export(parse_tojson_filter) export(parse_tojson_filter_eq) export(parse_tojson_filter_in) @@ -34,3 +38,4 @@ export(validate_ees_id) export(validate_page_size) export(validate_time_periods) export(warning_max_pages) +importFrom(data.table,":=") diff --git a/R/api_url.R b/R/api_url.R index d60a2d4..26a0b05 100644 --- a/R/api_url.R +++ b/R/api_url.R @@ -24,7 +24,7 @@ #' @param page Page number of query results to return #' @param api_version EES API version #' @param environment EES environment to connect to: "dev", "test", "preprod" or "prod" -#' @param verbose Run with additional contextual messaging, logical, default = FALSE +#' @param verbose Run with additional contextual messaging. Logical, default = FALSE #' @return A string containing the URL for connecting to the EES API #' @export #' diff --git a/R/eesyapi-package.R b/R/eesyapi-package.R new file mode 100644 index 0000000..d8900b1 --- /dev/null +++ b/R/eesyapi-package.R @@ -0,0 +1,7 @@ +#' @keywords internal +"_PACKAGE" + +## usethis namespace: start +#' @importFrom data.table := +## usethis namespace: end +NULL diff --git a/R/examples.R b/R/examples.R index ac82b9c..a230707 100644 --- a/R/examples.R +++ b/R/examples.R @@ -1,5 +1,4 @@ #' Example ID -#' #' @description #' This function returns examples of working IDs that can be used with the API. #' @@ -94,6 +93,36 @@ example_id <- function( } } +#' Example raw data +#' +#' @description +#' Download some example raw data. Mainly intended for use in developing / testing the sqid parsing +#' or as an example of getting raw data if any end users would prefer to do the sqid parsing +#' themselves. +#' +#' @inheritParams example_id +#' @param size Number of rows to return (max = 1000) +#' +#' @return Nested list form of example data from the API +#' @export +#' +#' @examples +#' example_data_raw() +example_data_raw <- function( + group = "attendance", + size = 32) { + eesyapi::api_url( + "get-data", + dataset_id = example_id(group = group), + indicators = example_id("indicator", group = group), + page = 1, page_size = size + ) |> + httr::GET() |> + httr::content("text") |> + jsonlite::fromJSON() |> + magrittr::use_series("results") +} + #' Create an example json query string #' @description #' Create an example json query string for use in examples and tests @@ -135,13 +164,13 @@ example_geography_query <- function(level = "nat_yorks") { return_level = c("NAT", "REG"), search_level = c("NAT", "REG"), identifier_type = c("code", "code"), - identifier = c("E92000001", "E12000002") + identifier = c("E92000001", "E12000003") ), nat_yorks_yorkslas = data.frame( return_level = c("NAT", "REG", "LA"), search_level = c("NAT", "REG", "REG"), identifier_type = c("code", "code", "code"), - identifier = c("E92000001", "E12000004", "E12000004") + identifier = c("E92000001", "E12000003", "E12000003") ) ) example_geography_queries |> diff --git a/R/get_dataset.R b/R/get_dataset.R index c2e0094..a61ef7e 100644 --- a/R/get_dataset.R +++ b/R/get_dataset.R @@ -57,7 +57,7 @@ get_dataset <- function( message(paste("Total number of pages: ", response_json$paging$totalPages)) } dfresults <- response_json$results |> - eesyapi::parse_api_dataset(verbose = verbose) + eesyapi::parse_api_dataset(dataset_id = dataset_id, verbose = verbose) # Unless the user has requested a specific page, then assume they'd like all pages collated and # recursively run the query. if (is.null(page)) { diff --git a/R/get_meta.R b/R/get_meta.R index b4986fe..9ea45e6 100644 --- a/R/get_meta.R +++ b/R/get_meta.R @@ -121,6 +121,7 @@ parse_meta_location_ids <- function(api_meta_locations, location_items_i <- api_meta_locations$options |> magrittr::extract2(i) |> dplyr::mutate( + geographic_level_code = api_meta_locations$level$code[i], geographic_level = api_meta_locations$level$label[i] ) |> dplyr::rename(item_id = "id") diff --git a/R/parse_api_dataset.R b/R/parse_api_dataset.R index 1d34906..986ae7f 100644 --- a/R/parse_api_dataset.R +++ b/R/parse_api_dataset.R @@ -11,24 +11,19 @@ #' parse_api_dataset() #' #' @param api_data_result A json data result list as returned from the API -#' @param dataset_id ID of data set to be connected to. -#' @param verbose Run in verbose mode, logical, default = FALSE +#' @inheritParams api_url #' #' @return Data frame containing API data results #' @export #' #' @examples -#' api_url( -#' "get-data", -#' dataset_id = example_id(), indicators = example_id("indicator"), page_size = 10 -#' ) |> -#' httr::GET() |> -#' httr::content("text") |> -#' jsonlite::fromJSON() |> -#' parse_api_dataset() +#' example_data_raw(group = "attendance") |> +#' parse_api_dataset(example_id(group = "attendance")) parse_api_dataset <- function( api_data_result, - dataset_id = NULL, + dataset_id, + dataset_version = NULL, + api_version = NULL, verbose = FALSE) { if (!is.null(dataset_id)) { eesyapi::validate_ees_id(dataset_id, level = "dataset") @@ -41,12 +36,20 @@ parse_api_dataset <- function( print(names(api_data_result$locations)) print(names(api_data_result$filters)) } + meta <- eesyapi::get_meta( + dataset_id, + dataset_version = dataset_version, + api_version = api_version + ) dplyr::bind_cols( api_data_result$timePeriod, data.frame(geographic_level = api_data_result$geographicLevel), - api_data_result$locations, - api_data_result$filters, - api_data_result$values + api_data_result$locations |> + eesyapi::parse_sqids_locations(meta), + api_data_result$filters |> + eesyapi::parse_sqids_filters(meta), + api_data_result$values |> + eesyapi::parse_sqids_indicators(meta), ) # Next aim here is to pull in the meta data automatically at this point to translate # all the API codes... diff --git a/R/parse_sqids.R b/R/parse_sqids.R new file mode 100644 index 0000000..aac1b5d --- /dev/null +++ b/R/parse_sqids.R @@ -0,0 +1,120 @@ +#' Parse location sqids +#' +#' @description +#' The API uses unique IDs (sqids) to identify each location in a data set. This function parses +#' those into the corresponding location codes and names based on the meta data stored on the API +#' for the data set. +#' +#' @inheritParams parse_sqids_filters +#' @param locations A set of location columns as taken from a data set downloaded from the API +#' +#' @return Data frame of parsed geography information +#' @export +#' +#' @examples +#' example_data_raw() |> +#' magrittr::use_series("locations") |> +#' parse_sqids_locations(get_meta(example_id(group = "attendance"))) +parse_sqids_locations <- function(locations, meta, verbose = FALSE) { + lookup <- meta |> + magrittr::use_series("locations") |> + dplyr::filter(!!rlang::sym("geographic_level_code") %in% names(locations)) |> + dplyr::rename(name = "label") + for (level in names(locations)) { + locations <- locations |> + dplyr::rename("item_id" = !!rlang::sym(level)) |> + dplyr::left_join( + lookup |> + dplyr::filter(!!rlang::sym("geographic_level_code") == level) |> + dplyr::select(-dplyr::all_of(c("geographic_level_code", "geographic_level"))) |> + dplyr::rename_with(~ paste0(tolower(level), "_", .x), !dplyr::matches("item_id")), + by = dplyr::join_by("item_id") + ) |> + dplyr::select(-"item_id") + } + return( + locations |> + dplyr::select( + dplyr::where( + ~ !all(is.na(.x)) + ) + ) + ) +} + +#' Parse IDs in a set of filters +#' +#' @description +#' The API uses unique IDs (sqids) to identify each filter column and its contents (filter items). +#' This function parses those into the data creators' id and item labels based on the meta data +#' stored on the API for the data set. +#' +#' @param filters A set of filter item columns as taken from a data set downloaded from the API +#' @param meta Meta data for the data set as provided by `get_meta()` +#' @param verbose Run in verbose mode with debugging messages +#' +#' @return Data frame +#' @export +#' +#' @examples +#' example_data_raw() |> +#' magrittr::use_series("filters") |> +#' parse_sqids_filters(get_meta(example_id(group = "attendance"))) +parse_sqids_filters <- function(filters, meta, verbose = FALSE) { + filter_ids <- meta |> + magrittr::use_series("filter_columns") |> + dplyr::filter(!!rlang::sym("col_id") %in% colnames(filters)) |> + dplyr::pull("col_id") + if (verbose) { + print(filter_ids) + } + for (column_sqid in filter_ids) { + col_name <- meta |> + magrittr::use_series("filter_columns") |> + dplyr::filter(!!rlang::sym("col_id") == column_sqid) |> + dplyr::pull("col_name") + if (verbose) { + message("Matched ", column_sqid, " to ", col_name) + } + lookup <- meta |> + magrittr::use_series("filter_items") |> + dplyr::filter(!!rlang::sym("col_id") == column_sqid) |> + dplyr::select("item_label", "item_id") |> + dplyr::rename( + !!rlang::sym(col_name) := "item_label", + !!rlang::sym(column_sqid) := "item_id" + ) + filters <- filters |> + dplyr::left_join(lookup, by = column_sqid) |> + dplyr::select(-dplyr::all_of(column_sqid)) + } + return(filters) +} + +#' Parse IDs in a set of indicators +#' +#' @description +#' The API uses unique IDs (sqids) to identify each indicator column. This function parses those +#' into the data creators' column names based on the meta data stored on the API for the data set. +#' +#' @inheritParams parse_sqids_filters +#' @param indicators A set of indicator columns as taken from a data set downloaded from the API +#' +#' @return Data frame +#' @export +#' +#' @examples +#' example_data_raw(group = "attendance") |> +#' magrittr::use_series("values") |> +#' parse_sqids_indicators(get_meta(example_id(group = "attendance"))) +parse_sqids_indicators <- function(indicators, meta, verbose = FALSE) { + indicator_ids <- meta |> + magrittr::use_series("indicators") |> + dplyr::filter(!!rlang::sym("col_id") %in% colnames(indicators)) + indicator_lookup <- indicator_ids |> + dplyr::pull("col_id") + names(indicator_lookup) <- indicator_ids |> dplyr::pull("col_name") + indicators <- indicators |> + dplyr::rename(dplyr::all_of(indicator_lookup)) + return(indicators) +} diff --git a/R/post_dataset.R b/R/post_dataset.R index ce9c038..aa539e5 100644 --- a/R/post_dataset.R +++ b/R/post_dataset.R @@ -75,7 +75,9 @@ post_dataset <- function( json_body <- readLines(json_query) |> paste0(collapse = "\n") } else { - message("Parsing query options") + if (verbose) { + message("Parsing query options") + } json_body <- json_query } } else { @@ -119,7 +121,7 @@ post_dataset <- function( message(paste("Total number of pages: ", response_json$paging$totalPages)) } dfresults <- response_json$results |> - eesyapi::parse_api_dataset(verbose = verbose) + eesyapi::parse_api_dataset(dataset_id, verbose = verbose) # Unless the user has requested a specific page, then assume they'd like all pages collated and # recursively run the query. if (is.null(page) && is.null(json_query)) { diff --git a/R/post_dataset_utils.R b/R/post_dataset_utils.R index 063ea74..7674e58 100644 --- a/R/post_dataset_utils.R +++ b/R/post_dataset_utils.R @@ -9,7 +9,7 @@ #' #' @inheritParams api_url #' @inheritParams parse_tojson_geographies -#' @param debug Run POST query in debug mode: logic, default: FALSE +#' @param debug Run POST query in debug mode. Logical, default = FALSE #' #' @return String containing json query body for use with http POST request #' @export diff --git a/_pkgdown.yml b/_pkgdown.yml index 291b7f4..c32d6e6 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -35,11 +35,12 @@ reference: - get_dataset - post_dataset - parse_api_dataset + - starts_with("parse_sqid") -- title: Examples - desc: Functions to create useful example cases for tests and code examples +- title: Generate example IDs and data + desc: These functions are used widely to create working example code and tests contents: - - starts_with("example_") + - starts_with("example") - title: Validation functions desc: These functions are used across the package to validate elements being passed as part of an API url or query. diff --git a/man/api_url.Rd b/man/api_url.Rd index 00eb32d..560854a 100644 --- a/man/api_url.Rd +++ b/man/api_url.Rd @@ -51,7 +51,7 @@ of "get-summary", "get-meta", "get-data" or "post-data"} \item{environment}{EES environment to connect to: "dev", "test", "preprod" or "prod"} -\item{verbose}{Run with additional contextual messaging, logical, default = FALSE} +\item{verbose}{Run with additional contextual messaging. Logical, default = FALSE} } \value{ A string containing the URL for connecting to the EES API diff --git a/man/eesyapi-package.Rd b/man/eesyapi-package.Rd new file mode 100644 index 0000000..52368a0 --- /dev/null +++ b/man/eesyapi-package.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/eesyapi-package.R +\docType{package} +\name{eesyapi-package} +\alias{eesyapi} +\alias{eesyapi-package} +\title{eesyapi: EES-y API} +\description{ +\if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} + +An R package with useful utility functions for connecting to, and processing data from, the DfE's explore education statistics API. +} +\seealso{ +Useful links: +\itemize{ + \item \url{https://dfe-analytical-services.github.io/eesyapi} +} + +} +\author{ +\strong{Maintainer}: Rich Bielby \email{richard.bielby@education.gov.uk} (\href{https://orcid.org/0000-0001-9070-9969}{ORCID}) + +Authors: +\itemize{ + \item Cam Race \email{cameron.race@education.gov.uk} +} + +Other contributors: +\itemize{ + \item Laura Selby \email{laura.selby@education.gov.uk} [contributor] +} + +} +\keyword{internal} diff --git a/man/example_data_raw.Rd b/man/example_data_raw.Rd new file mode 100644 index 0000000..92442ce --- /dev/null +++ b/man/example_data_raw.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/examples.R +\name{example_data_raw} +\alias{example_data_raw} +\title{Example raw data} +\usage{ +example_data_raw(group = "attendance", size = 32) +} +\arguments{ +\item{group}{Choose the publication group of examples to use. Can be "attendance".} + +\item{size}{Number of rows to return (max = 1000)} +} +\value{ +Nested list form of example data from the API +} +\description{ +Download some example raw data. Mainly intended for use in developing / testing the sqid parsing +or as an example of getting raw data if any end users would prefer to do the sqid parsing +themselves. +} +\examples{ +example_data_raw() +} diff --git a/man/get_dataset.Rd b/man/get_dataset.Rd index ae80656..4e15e07 100644 --- a/man/get_dataset.Rd +++ b/man/get_dataset.Rd @@ -43,7 +43,7 @@ of "get-summary", "get-meta", "get-data" or "post-data"} \item{parse}{Logical flag to activate parsing of the results. Default: TRUE} -\item{verbose}{Run with additional contextual messaging, logical, default = FALSE} +\item{verbose}{Run with additional contextual messaging. Logical, default = FALSE} } \value{ Data frame containing query results of an API data set diff --git a/man/get_meta.Rd b/man/get_meta.Rd index 467ad6b..3ab6058 100644 --- a/man/get_meta.Rd +++ b/man/get_meta.Rd @@ -19,7 +19,7 @@ of "get-summary", "get-meta", "get-data" or "post-data"} \item{api_version}{EES API version} -\item{verbose}{Run with additional contextual messaging, logical, default = FALSE} +\item{verbose}{Run with additional contextual messaging. Logical, default = FALSE} } \value{ List of data frames containing a data set's meta data diff --git a/man/get_meta_response.Rd b/man/get_meta_response.Rd index dfc5176..1623ac3 100644 --- a/man/get_meta_response.Rd +++ b/man/get_meta_response.Rd @@ -22,7 +22,7 @@ of "get-summary", "get-meta", "get-data" or "post-data"} \item{parse}{Parse result into structured list} -\item{verbose}{Run with additional contextual messaging, logical, default = FALSE} +\item{verbose}{Run with additional contextual messaging. Logical, default = FALSE} } \value{ Results of query to API meta data endpoint diff --git a/man/parse_api_dataset.Rd b/man/parse_api_dataset.Rd index bbe935a..f37edf2 100644 --- a/man/parse_api_dataset.Rd +++ b/man/parse_api_dataset.Rd @@ -4,14 +4,25 @@ \alias{parse_api_dataset} \title{Parse contents of API data set json output} \usage{ -parse_api_dataset(api_data_result, dataset_id = NULL, verbose = FALSE) +parse_api_dataset( + api_data_result, + dataset_id, + dataset_version = NULL, + api_version = NULL, + verbose = FALSE +) } \arguments{ \item{api_data_result}{A json data result list as returned from the API} -\item{dataset_id}{ID of data set to be connected to.} +\item{dataset_id}{ID of data set to be connected to. This is required if the endpoint is one +of "get-summary", "get-meta", "get-data" or "post-data"} -\item{verbose}{Run in verbose mode, logical, default = FALSE} +\item{dataset_version}{Version of data set to be connected to} + +\item{api_version}{EES API version} + +\item{verbose}{Run with additional contextual messaging. Logical, default = FALSE} } \value{ Data frame containing API data results @@ -27,12 +38,6 @@ jsonlite::fromJSON() |> parse_api_dataset() } \examples{ -api_url( - "get-data", - dataset_id = example_id(), indicators = example_id("indicator"), page_size = 10 -) |> - httr::GET() |> - httr::content("text") |> - jsonlite::fromJSON() |> - parse_api_dataset() +example_data_raw(group = "attendance") |> + parse_api_dataset(example_id(group = "attendance")) } diff --git a/man/parse_meta_filter_columns.Rd b/man/parse_meta_filter_columns.Rd index 85d82fa..45894de 100644 --- a/man/parse_meta_filter_columns.Rd +++ b/man/parse_meta_filter_columns.Rd @@ -9,7 +9,7 @@ parse_meta_filter_columns(api_meta_filters, verbose = FALSE) \arguments{ \item{api_meta_filters}{Filter information provided by the API output} -\item{verbose}{Run with additional contextual messaging, logical, default = FALSE} +\item{verbose}{Run with additional contextual messaging. Logical, default = FALSE} } \value{ data frame containing column names and labels diff --git a/man/parse_meta_filter_item_ids.Rd b/man/parse_meta_filter_item_ids.Rd index 2159672..dae4826 100644 --- a/man/parse_meta_filter_item_ids.Rd +++ b/man/parse_meta_filter_item_ids.Rd @@ -9,7 +9,7 @@ parse_meta_filter_item_ids(api_meta_filters, verbose = FALSE) \arguments{ \item{api_meta_filters}{Filter information provided by the API output} -\item{verbose}{Run with additional contextual messaging, logical, default = FALSE} +\item{verbose}{Run with additional contextual messaging. Logical, default = FALSE} } \value{ Data frame containing filter item codes matched to filter item labels and col_name diff --git a/man/parse_meta_location_ids.Rd b/man/parse_meta_location_ids.Rd index d581cac..37895cd 100644 --- a/man/parse_meta_location_ids.Rd +++ b/man/parse_meta_location_ids.Rd @@ -9,7 +9,7 @@ parse_meta_location_ids(api_meta_locations, verbose = FALSE) \arguments{ \item{api_meta_locations}{Locations information provided by the API output} -\item{verbose}{Run with additional contextual messaging, logical, default = FALSE} +\item{verbose}{Run with additional contextual messaging. Logical, default = FALSE} } \value{ Data frame containing location item codes matched diff --git a/man/parse_meta_time_periods.Rd b/man/parse_meta_time_periods.Rd index c576c52..62b4884 100644 --- a/man/parse_meta_time_periods.Rd +++ b/man/parse_meta_time_periods.Rd @@ -9,7 +9,7 @@ parse_meta_time_periods(api_meta_time_periods, verbose = FALSE) \arguments{ \item{api_meta_time_periods}{Time periods information provided by the API output} -\item{verbose}{Run with additional contextual messaging, logical, default = FALSE} +\item{verbose}{Run with additional contextual messaging. Logical, default = FALSE} } \value{ Data frame containing location item codes matched diff --git a/man/parse_sqids_filters.Rd b/man/parse_sqids_filters.Rd new file mode 100644 index 0000000..c3622ab --- /dev/null +++ b/man/parse_sqids_filters.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/parse_sqids.R +\name{parse_sqids_filters} +\alias{parse_sqids_filters} +\title{Parse IDs in a set of filters} +\usage{ +parse_sqids_filters(filters, meta, verbose = FALSE) +} +\arguments{ +\item{filters}{A set of filter item columns as taken from a data set downloaded from the API} + +\item{meta}{Meta data for the data set as provided by \code{get_meta()}} + +\item{verbose}{Run in verbose mode with debugging messages} +} +\value{ +Data frame +} +\description{ +The API uses unique IDs (sqids) to identify each filter column and its contents (filter items). +This function parses those into the data creators' id and item labels based on the meta data +stored on the API for the data set. +} +\examples{ +example_data_raw() |> + magrittr::use_series("filters") |> + parse_sqids_filters(get_meta(example_id(group = "attendance"))) +} diff --git a/man/parse_sqids_indicators.Rd b/man/parse_sqids_indicators.Rd new file mode 100644 index 0000000..53b114e --- /dev/null +++ b/man/parse_sqids_indicators.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/parse_sqids.R +\name{parse_sqids_indicators} +\alias{parse_sqids_indicators} +\title{Parse IDs in a set of indicators} +\usage{ +parse_sqids_indicators(indicators, meta, verbose = FALSE) +} +\arguments{ +\item{indicators}{A set of indicator columns as taken from a data set downloaded from the API} + +\item{meta}{Meta data for the data set as provided by \code{get_meta()}} + +\item{verbose}{Run in verbose mode with debugging messages} +} +\value{ +Data frame +} +\description{ +The API uses unique IDs (sqids) to identify each indicator column. This function parses those +into the data creators' column names based on the meta data stored on the API for the data set. +} +\examples{ +example_data_raw(group = "attendance") |> + magrittr::use_series("values") |> + parse_sqids_indicators(get_meta(example_id(group = "attendance"))) +} diff --git a/man/parse_sqids_locations.Rd b/man/parse_sqids_locations.Rd new file mode 100644 index 0000000..da656aa --- /dev/null +++ b/man/parse_sqids_locations.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/parse_sqids.R +\name{parse_sqids_locations} +\alias{parse_sqids_locations} +\title{Parse location sqids} +\usage{ +parse_sqids_locations(locations, meta, verbose = FALSE) +} +\arguments{ +\item{locations}{A set of location columns as taken from a data set downloaded from the API} + +\item{meta}{Meta data for the data set as provided by \code{get_meta()}} + +\item{verbose}{Run in verbose mode with debugging messages} +} +\value{ +Data frame of parsed geography information +} +\description{ +The API uses unique IDs (sqids) to identify each location in a data set. This function parses +those into the corresponding location codes and names based on the meta data stored on the API +for the data set. +} +\examples{ +example_data_raw() |> + magrittr::use_series("locations") |> + parse_sqids_locations(get_meta(example_id(group = "attendance"))) +} diff --git a/man/parse_tojson_params.Rd b/man/parse_tojson_params.Rd index 36468db..a94aa15 100644 --- a/man/parse_tojson_params.Rd +++ b/man/parse_tojson_params.Rd @@ -29,9 +29,9 @@ locations to be queried.} \item{page_size}{Number of results to return in a single query} -\item{debug}{Run POST query in debug mode: logic, default: FALSE} +\item{debug}{Run POST query in debug mode. Logical, default = FALSE} -\item{verbose}{Run with additional contextual messaging, logical, default = FALSE} +\item{verbose}{Run with additional contextual messaging. Logical, default = FALSE} } \value{ String containing json query body for use with http POST request diff --git a/man/post_dataset.Rd b/man/post_dataset.Rd index 0f07b5a..f6781a1 100644 --- a/man/post_dataset.Rd +++ b/man/post_dataset.Rd @@ -45,9 +45,9 @@ locations to be queried.} \item{parse}{Logical flag to activate parsing of the results. Default: TRUE} -\item{debug}{Run POST query in debug mode: logic, default: FALSE} +\item{debug}{Run POST query in debug mode. Logical, default = FALSE} -\item{verbose}{Run with additional contextual messaging, logical, default = FALSE} +\item{verbose}{Run with additional contextual messaging. Logical, default = FALSE} } \value{ Data frame containing query results of an API data set diff --git a/man/query_dataset.Rd b/man/query_dataset.Rd index 892fe1a..71e85a1 100644 --- a/man/query_dataset.Rd +++ b/man/query_dataset.Rd @@ -51,9 +51,9 @@ locations to be queried.} \item{page}{Page number of query results to return} -\item{debug}{Run POST query in debug mode: logic, default: FALSE} +\item{debug}{Run POST query in debug mode. Logical, default = FALSE} -\item{verbose}{Run with additional contextual messaging, logical, default = FALSE} +\item{verbose}{Run with additional contextual messaging. Logical, default = FALSE} } \value{ Data frame containing query results diff --git a/tests/testthat/test-query_dataset.R b/tests/testthat/test-query_dataset.R index b5fb042..23a4709 100644 --- a/tests/testthat/test-query_dataset.R +++ b/tests/testthat/test-query_dataset.R @@ -87,13 +87,13 @@ test_that("Geography query returns expected geographies", { geographies = eesyapi::example_id("location_ids", group = "attendance"), filter_items = eesyapi::example_id("filter_item", group = "attendance") ) |> - dplyr::select(geographic_level, NAT, REG) |> + dplyr::select("geographic_level", "nat_code", "reg_code") |> dplyr::distinct() |> dplyr::arrange(geographic_level), data.frame( geographic_level = c("NAT", "REG"), - NAT = c("dP0Zw", "dP0Zw"), - REG = c(NA, "rg3Nj") + nat_code = rep("E92000001", 2), + reg_code = c(NA, "E12000004") ) ) }) @@ -121,17 +121,23 @@ test_that("Test filter-combinations POST dataset query", { geographies = eesyapi::example_id("location_ids", group = "attendance"), filter_items = eesyapi::example_id("filter_items_short", group = "attendance") ) |> - dplyr::select("5TYdi", "mU59K", "Db3Qe", "emJuS", "4kdUZ") |> + dplyr::select( + "attendance_status", + "attendance_type", + "day_number", + "establishment_phase", + "reason" + ) |> dplyr::distinct() expect_equal( query_result, data.frame( - `5TYdi` = c("uLQo4", "uLQo4", "uLQo4", "uLQo4"), - `mU59K` = c("bBrtT", "bBrtT", "bBrtT", "bBrtT"), - `Db3Qe` = c("pmRSo", "pmRSo", "pmRSo", "pmRSo"), - `emJuS` = c("CvuId", "6AXrf", "CvuId", "6AXrf"), - `4kdUZ` = c("ThDPJ", "ThDPJ", "crH31", "crH31") - ) |> dplyr::rename_with(~ stringr::str_replace_all(., "X", "")) + attendance_status = rep("Attendance", 4), + attendance_type = rep(c("Present", "Approved educational activity"), 2), + day_number = rep("Total", 4), + establishment_phase = c(rep("Secondary", 2), rep("Special", 2)), + reason = rep("Total", 4) + ) ) }) diff --git a/tests/testthat/testdata/example_json-from-file_dataset.rds b/tests/testthat/testdata/example_json-from-file_dataset.rds index f2c9f80..2d388d9 100644 Binary files a/tests/testthat/testdata/example_json-from-file_dataset.rds and b/tests/testthat/testdata/example_json-from-file_dataset.rds differ diff --git a/tests/testthat/testdata/example_json-from-string_dataset.rds b/tests/testthat/testdata/example_json-from-string_dataset.rds index b92945e..8e33b38 100644 Binary files a/tests/testthat/testdata/example_json-from-string_dataset.rds and b/tests/testthat/testdata/example_json-from-string_dataset.rds differ diff --git a/tests/testthat/testdata/example_meta_parsed.rds b/tests/testthat/testdata/example_meta_parsed.rds index 692ca01..bf5f365 100644 Binary files a/tests/testthat/testdata/example_meta_parsed.rds and b/tests/testthat/testdata/example_meta_parsed.rds differ diff --git a/tests/testthat/testdata/example_post_dataset.rds b/tests/testthat/testdata/example_post_dataset.rds index 18b9888..5d27b45 100644 Binary files a/tests/testthat/testdata/example_post_dataset.rds and b/tests/testthat/testdata/example_post_dataset.rds differ