diff --git a/DESCRIPTION b/DESCRIPTION index 7f9ffb6..dd1cf9e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,7 +22,8 @@ Suggests: tidyr VignetteBuilder: knitr Imports: - sf + sf, + utils Depends: R (>= 2.10) Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 7900a6c..2d57f3d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,3 +1,4 @@ # Generated by roxygen2: do not edit by hand export(boundaries_get) +export(boundaries_select) diff --git a/R/boundaries_select.R b/R/boundaries_select.R new file mode 100644 index 0000000..edf71db --- /dev/null +++ b/R/boundaries_select.R @@ -0,0 +1,78 @@ +#' Interactively Retrieve Geographical Boundaries +#' +#' Constructs a valid combination of geometry type, year and detail level and +#' downloads the selected boundary. +#' +#' @return a `sf` object with the selected boundaries. +#' +#' +#' @export +#' +boundaries_select <- function() { + # Boundary types ---------------------------------------------------------- + boundary_types <- levels(ons_boundaries$boundary_type) + + # Use the menu function to prompt the user to choose an option + choice_boundary_type_n <- utils::menu( + boundary_types, + title = "Please choose the boundary type:" + ) + + choice_boundary_type <- boundary_types[choice_boundary_type_n] + + cat("You chose:", choice_boundary_type, "\n") + + + # Boundary ---------------------------------------------------------------- + boundaries <- levels(droplevels( + ons_boundaries[ons_boundaries$boundary_type == choice_boundary_type, "boundary"] + )) + + choice_boundary_n <- utils::menu(boundaries, + title = paste(choice_boundary_type, "has the following boundaries. Please choose the boundary name you'd like to download:") + ) + + choice_boundary <- boundaries[choice_boundary_n] + + cat("You chose:", choice_boundary, "\n") + + # Year -------------------------------------------------------------------- + + years <- levels(as.factor( + ons_boundaries[ons_boundaries$boundary == choice_boundary, "year"] + )) + + choice_years_n <- utils::menu( + years, + title = paste(choice_boundary, "were updated in the following years. Please choose the year name you'd like to download:") + ) + + choice_year <- as.numeric(years[choice_years_n]) + + print(choice_year) + + # Detail level ----------------------------------------------------------- + detail_levels <- levels(droplevels( + ons_boundaries[ons_boundaries$boundary == choice_boundary & ons_boundaries$year == choice_year, "detail_level"] + )) + + choice_detail_levels_n <- utils::menu( + detail_levels, + title = "Choose the detail level you'd like to download" + ) + + choice_detail_levels <- detail_levels[choice_detail_levels_n] + + # Download --------------------------------------------------------------- + #return(paste(choice_boundary, choice_year, choice_detail_levels, sep = "_")) + return(boundaries_get(choice_boundary, choice_year, choice_detail_levels)) + + # Check if the user made a valid choice + # if (choice_boundary_type> 0) { + # cat("You chose:", choice_boundary_type, "\n") + # return(choice_boundary_type) + # } else { + # cat("No valid option was chosen.\n") + # return(NULL) + # } +} diff --git a/man/boundaries_select.Rd b/man/boundaries_select.Rd new file mode 100644 index 0000000..2fd5492 --- /dev/null +++ b/man/boundaries_select.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/boundaries_select.R +\name{boundaries_select} +\alias{boundaries_select} +\title{Interactively Retrieve Geographical Boundaries} +\usage{ +boundaries_select() +} +\value{ +a \code{sf} object with the selected boundaries. +} +\description{ +Constructs a valid combination of geometry type, year and detail level and +downloads the selected boundary. +} diff --git a/man/figures/hex-logo.svg b/man/figures/hex-logo.svg new file mode 100644 index 0000000..a477ed0 --- /dev/null +++ b/man/figures/hex-logo.svg @@ -0,0 +1,144 @@ + + + +ukgeographies"A contrasted hexagon stating 'vis2text'" diff --git a/tests/testthat/test-boundaries_select.R b/tests/testthat/test-boundaries_select.R new file mode 100644 index 0000000..8849056 --- /dev/null +++ b/tests/testthat/test-boundaries_select.R @@ -0,0 +1,3 @@ +test_that("multiplication works", { + expect_equal(2 * 2, 4) +})