-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
Add access to education services
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#' Get locations of education services in Europe | ||
#' | ||
#' @family infrastructure | ||
#' | ||
#' @description | ||
#' The dataset contains information on main education services by Member States. | ||
#' | ||
#' @return A `POINT` [`sf`][sf::st_sf] object. | ||
#' | ||
#' @author dieghernan, <https://github.com/dieghernan/> | ||
#' | ||
#' @source | ||
#' <https://ec.europa.eu/eurostat/web/gisco/geodata/basic-services> | ||
#' | ||
#' @inheritParams gisco_get_countries | ||
#' | ||
#' @inheritSection gisco_get_countries About caching | ||
#' | ||
#' @details | ||
#' Files are distributed on EPSG:4326. Metadata available on | ||
#' <https://gisco-services.ec.europa.eu/pub/education/metadata.pdf>. | ||
#' | ||
#' @seealso [gisco_get_countries()] | ||
#' @examplesIf gisco_check_access() | ||
#' \donttest{ | ||
#' | ||
#' edu_BEL <- gisco_get_education(country = "Belgium") | ||
#' | ||
#' # Plot if downloaded | ||
#' if (nrow(edu_BEL) > 3) { | ||
#' library(ggplot2) | ||
#' ggplot(edu_BEL) + | ||
#' geom_sf(shape = 21, size = 0.15) | ||
#' } | ||
#' } | ||
#' @export | ||
gisco_get_education <- function(cache = TRUE, update_cache = FALSE, | ||
cache_dir = NULL, verbose = FALSE, | ||
country = NULL) { | ||
# Given vars | ||
epsg <- "4326" | ||
ext <- "gpkg" | ||
|
||
if (!is.null(country)) { | ||
country_get <- gsc_helper_countrynames(country, "eurostat") | ||
} else { | ||
country_get <- "EU" | ||
} | ||
|
||
|
||
api_entry <- paste0( | ||
"https://gisco-services.ec.europa.eu/pub/education", | ||
"/gpkg/", country_get, ".gpkg" | ||
) | ||
|
||
n_cnt <- seq_len(length(api_entry)) | ||
|
||
ress <- lapply(n_cnt, function(x) { | ||
api <- api_entry[x] | ||
filename <- basename(api) | ||
|
||
|
||
if (cache) { | ||
# Guess source to load | ||
namefileload <- gsc_api_cache( | ||
api, filename, cache_dir, update_cache, | ||
verbose | ||
) | ||
} else { | ||
namefileload <- api | ||
} | ||
|
||
if (is.null(namefileload)) { | ||
return(NULL) | ||
} | ||
|
||
data_sf <- gsc_api_load(namefileload, epsg, ext, cache, verbose) | ||
|
||
data_sf | ||
}) | ||
|
||
data_sf_all <- do.call("rbind", ress) | ||
|
||
return(data_sf_all) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
test_that("Education online", { | ||
skip_on_cran() | ||
skip_if_gisco_offline() | ||
|
||
expect_silent(gisco_get_education(country = "LU", cache = FALSE)) | ||
expect_silent(gisco_get_education(country = "Denmark")) | ||
expect_message(gisco_get_education(verbose = TRUE, country = "BE")) | ||
|
||
# Several countries | ||
nn <- gisco_get_education(country = c("LU", "DK", "BE")) | ||
|
||
expect_length(unique(nn$cc), 3) | ||
|
||
# Full | ||
eufull <- gisco_get_education() | ||
|
||
expect_gt(length(unique(eufull$cc)), 10) | ||
}) | ||
|
||
test_that("Offline", { | ||
options(giscoR_test_offline = TRUE) | ||
expect_message( | ||
n <- gisco_get_education(update_cache = TRUE), | ||
"not reachable" | ||
) | ||
expect_null(n) | ||
options(giscoR_test_offline = FALSE) | ||
}) |