Skip to content

Commit

Permalink
Merge pull request #83 from rOpenGov/education
Browse files Browse the repository at this point in the history
Add access to education services
  • Loading branch information
dieghernan committed May 20, 2024
2 parents c5ec25e + b5e2cee commit 35eb00d
Show file tree
Hide file tree
Showing 19 changed files with 236 additions and 19 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(gisco_get_airports)
export(gisco_get_coastallines)
export(gisco_get_communes)
export(gisco_get_countries)
export(gisco_get_education)
export(gisco_get_grid)
export(gisco_get_healthcare)
export(gisco_get_lau)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# giscoR (development version)

- New functions:
- `gisco_get_education()`.
- Update `gisco_db` with the most up-to-date released data.
- Default year of some functions updated to the latest available data:
- `gisco_get_lau()` and `gisco_get_urban_audit()` default year now is
Expand Down
2 changes: 1 addition & 1 deletion R/gisco_get_countries.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
#'
#' @param country Optional. A character vector of country codes. It could be
#' either a vector of country names, a vector of ISO3 country codes or a
#' vector of Eurostat country codes. Mixed types (as `c("Turkey","US","FRA")`)
#' vector of Eurostat country codes. Mixed types (as `c("Italy","ES","FRA")`)
#' would not work. See also [countrycode::countrycode()].
#'
#' @param verbose Logical, displays information. Useful for debugging,
Expand Down
85 changes: 85 additions & 0 deletions R/gisco_get_education.R
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)
}
8 changes: 7 additions & 1 deletion R/gisco_get_healthcare.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@
#' \donttest{
#'
#' health_BEL <- gisco_get_healthcare(country = "Belgium")
#' health_BEL
#'
#' # Plot if downloaded
#' if (nrow(health_BEL) > 3) {
#' library(ggplot2)
#' ggplot(health_BEL) +
#' geom_sf(aes(color = emergency))
#' }
#' }
#' @export
gisco_get_healthcare <- function(cache = TRUE, update_cache = FALSE,
Expand Down
3 changes: 2 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ results](https://badges.cranchecks.info/worst/giscoR.svg)](https://cran.r-projec
[![Downloads](https://cranlogs.r-pkg.org/badges/giscoR)](https://CRAN.R-project.org/package=giscoR)
[![r-universe](https://ropengov.r-universe.dev/badges/giscoR)](https://ropengov.r-universe.dev/giscoR)
[![R-CMD-check](https://github.com/rOpenGov/giscoR/actions/workflows/check-full.yaml/badge.svg)](https://github.com/rOpenGov/giscoR/actions/workflows/check-full.yaml)
[![R-hub](https://github.com/rOpenGov/giscoR/actions/workflows/rhub.yaml/badge.svg)](https://github.com/rOpenGov/giscoR/actions/workflows/rhub.yaml)
[![codecov](https://codecov.io/gh/ropengov/giscoR/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ropengov/giscoR)
[![CodeFactor](https://www.codefactor.io/repository/github/ropengov/giscor/badge)](https://www.codefactor.io/repository/github/ropengov/giscor)
[![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.4317946-blue)](https://doi.org/10.5281/zenodo.4317946)
[![Project Status:
Active](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![status](https://tinyverse.netlify.com/badge/giscoR)](https://CRAN.R-project.org/package=giscoR)
[![status](https://tinyverse.netlify.app/status/giscoR)](https://CRAN.R-project.org/package=giscoR)

<!-- badges: end -->

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ results](https://badges.cranchecks.info/worst/giscoR.svg)](https://cran.r-projec
[![Downloads](https://cranlogs.r-pkg.org/badges/giscoR)](https://CRAN.R-project.org/package=giscoR)
[![r-universe](https://ropengov.r-universe.dev/badges/giscoR)](https://ropengov.r-universe.dev/giscoR)
[![R-CMD-check](https://github.com/rOpenGov/giscoR/actions/workflows/check-full.yaml/badge.svg)](https://github.com/rOpenGov/giscoR/actions/workflows/check-full.yaml)
[![R-hub](https://github.com/rOpenGov/giscoR/actions/workflows/rhub.yaml/badge.svg)](https://github.com/rOpenGov/giscoR/actions/workflows/rhub.yaml)
[![codecov](https://codecov.io/gh/ropengov/giscoR/branch/main/graph/badge.svg)](https://app.codecov.io/gh/ropengov/giscoR)
[![CodeFactor](https://www.codefactor.io/repository/github/ropengov/giscor/badge)](https://www.codefactor.io/repository/github/ropengov/giscor)
[![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.4317946-blue)](https://doi.org/10.5281/zenodo.4317946)
[![Project Status:
Active](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![status](https://tinyverse.netlify.com/badge/giscoR)](https://CRAN.R-project.org/package=giscoR)
[![status](https://tinyverse.netlify.app/status/giscoR)](https://CRAN.R-project.org/package=giscoR)

<!-- badges: end -->

Expand Down Expand Up @@ -186,7 +187,7 @@ We now download the data from Eurostat:
library(eurostat)
popdens <- get_eurostat("demo_r_d3dens") %>%
filter(TIME_PERIOD == "2021-01-01")
#> indexed 0B in 0s, 0B/sindexed 1.00TB in 0s, 442.30TB/s
#> indexed 0B in 0s, 0B/sindexed 1.00TB in 0s, 415.28TB/s
```

By last, we merge and manipulate the data for creating the final plot:
Expand Down
4 changes: 2 additions & 2 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
"applicationCategory": "cartography",
"isPartOf": "http://ropengov.org/",
"keywords": ["ropengov", "r", "spatial", "api-wrapper", "rstats", "r-package", "eurostat", "gisco", "thematic-maps", "eurostat-data", "cran", "ggplot2", "gis"],
"fileSize": "1218.668KB",
"fileSize": "1224.516KB",
"citation": [
{
"@type": "SoftwareSourceCode",
Expand All @@ -249,6 +249,6 @@
],
"releaseNotes": "https://github.com/rOpenGov/giscoR/blob/master/NEWS.md",
"readme": "https://github.com/rOpenGov/giscoR/blob/main/README.md",
"contIntegration": ["https://github.com/rOpenGov/giscoR/actions/workflows/check-full.yaml", "https://app.codecov.io/gh/ropengov/giscoR"],
"contIntegration": ["https://github.com/rOpenGov/giscoR/actions/workflows/check-full.yaml", "https://github.com/rOpenGov/giscoR/actions/workflows/rhub.yaml", "https://app.codecov.io/gh/ropengov/giscoR"],
"developmentStatus": "https://www.repostatus.org/#active"
}
2 changes: 1 addition & 1 deletion man/gisco_get.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/gisco_get_airports.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions man/gisco_get_education.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions man/gisco_get_healthcare.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/gisco_get_lau.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/gisco_get_nuts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/gisco_get_postalcodes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/gisco_get_urban_audit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions tests/testthat/test-gisco_get_education.R
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)
})
Loading

0 comments on commit 35eb00d

Please sign in to comment.