-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First working version of boundaries_select()
TODO: improve texts and add proper testing
- Loading branch information
Showing
6 changed files
with
243 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(boundaries_get) | ||
export(boundaries_select) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
# } | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test_that("multiplication works", { | ||
expect_equal(2 * 2, 4) | ||
}) |