Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating get_meta to handle 3-col info on filters and indicators #33

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: eesyapi
Title: EES-y API
Version: 0.2.0
Version: 0.2.1
Authors@R:
c(
person("Rich", "Bielby", , "[email protected]", role = c("aut", "cre"),
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export(parse_api_dataset)
export(parse_filter_in)
export(parse_meta_filter_columns)
export(parse_meta_filter_item_ids)
export(parse_meta_indicator_columns)
export(parse_meta_location_ids)
export(parse_meta_time_periods)
export(query_dataset)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# eesyapi 0.2.1

* Updated `get_meta()` to work with new API meta output (addition of id alongside col_name and label)
* Removed redundant function: `parse_meta_filter_columns()`
* Hex logo added for documentation

# eesyapi 0.2.0

* Creating publication querying functions:
Expand Down
28 changes: 6 additions & 22 deletions R/get_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ parse_meta_location_ids <- function(api_meta_locations) {
#' parse_meta_filter_columns()
parse_meta_filter_columns <- function(api_meta_filters) {
data.frame(
col_name = api_meta_filters$id,
col_id = api_meta_filters$id,
col_name = api_meta_filters$column,
label = api_meta_filters$label
)
}
Expand All @@ -163,13 +164,13 @@ parse_meta_filter_columns <- function(api_meta_filters) {
parse_meta_filter_item_ids <- function(api_meta_filters) {
nfilters <- length(api_meta_filters$id)
filter_items <- data.frame(
col_name = NA,
col_id = NA,
item_id = NA,
item_label = NA,
isAggregate = NA
)
filter_items <- filter_items |>
dplyr::filter(!is.na(filter_items$col_name))
dplyr::filter(!is.na(filter_items$col_id))
for (i in 1:nfilters) {
filter_items_i <- as.data.frame(
api_meta_filters$options[i]
Expand All @@ -178,33 +179,16 @@ parse_meta_filter_item_ids <- function(api_meta_filters) {
item_id = "id",
item_label = "label"
) |>
dplyr::mutate(col_name = api_meta_filters$id[i])
dplyr::mutate(col_id = api_meta_filters$id[i])
if (!("isAggregate" %in% names(filter_items_i))) {
filter_items_i <- filter_items_i |>
dplyr::mutate(isAggregate = NA)
}
filter_items <- filter_items |>
rbind(
filter_items_i |>
dplyr::select("col_name", "item_label", "item_id", default_item = "isAggregate")
dplyr::select("col_id", "item_label", "item_id", default_item = "isAggregate")
)
}
return(filter_items)
}

#' Parse API meta to give the indicator columns
#'
#' @param api_meta_indicators Indicator information provided by the API output
#'
#' @return data frame containing indicator column names and labels
#' @export
#'
#' @examples
#' get_meta_response(example_id())$indicators |>
#' parse_meta_indicator_columns()
parse_meta_indicator_columns <- function(api_meta_indicators) {
data.frame(
col_name = api_meta_indicators$id,
label = api_meta_indicators$label
)
}
21 changes: 0 additions & 21 deletions man/parse_meta_indicator_columns.Rd

This file was deleted.

16 changes: 16 additions & 0 deletions tests/testthat/seed_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

# Refresh all test data
seed_tests <- function() {
message("Updating publication list")
seed_get_publications()
message("Updating data catalogue list")
seed_get_data_catalogue()
message("Updating example meta data")
seed_get_meta()
}

# Refresh the publication list
Expand All @@ -35,3 +39,15 @@ seed_get_data_catalogue <- function() {
file = "tests/testthat/testdata/example_publication_datasets.rds"
)
}

# Refresh the data sets list from the standard example publication
seed_get_meta <- function() {
saveRDS(
eesyapi::get_meta_response(eesyapi::example_id()),
file = "tests/testthat/testdata/example_meta_unparsed.rds"
)
saveRDS(
eesyapi::get_meta(eesyapi::example_id()),
file = "tests/testthat/testdata/example_meta_parsed.rds"
)
}
2 changes: 1 addition & 1 deletion tests/testthat/test-get_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test_that("Filter item ids parsing works as expected", {
test_that("Indicator ids parsing works as expected", {
expect_equal(
readRDS("testdata/example_meta_unparsed.rds")$indicators |>
parse_meta_indicator_columns(),
parse_meta_filter_columns(),
readRDS("testdata/example_meta_parsed.rds")$indicators
)
})
Binary file modified tests/testthat/testdata/example_meta_parsed.rds
Binary file not shown.
Binary file modified tests/testthat/testdata/example_meta_unparsed.rds
Binary file not shown.
Loading