diff --git a/NAMESPACE b/NAMESPACE index 2a8957d7..1988463a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/NEWS.md b/NEWS.md index 84d8ae04..4e8f04c0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/gisco_get_countries.R b/R/gisco_get_countries.R index 1774faca..7d7e442f 100644 --- a/R/gisco_get_countries.R +++ b/R/gisco_get_countries.R @@ -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, diff --git a/R/gisco_get_education.R b/R/gisco_get_education.R new file mode 100644 index 00000000..23bc6203 --- /dev/null +++ b/R/gisco_get_education.R @@ -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, +#' +#' @source +#' +#' +#' @inheritParams gisco_get_countries +#' +#' @inheritSection gisco_get_countries About caching +#' +#' @details +#' Files are distributed on EPSG:4326. Metadata available on +#' . +#' +#' @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) +} diff --git a/R/gisco_get_healthcare.R b/R/gisco_get_healthcare.R index 7351bc1a..0fe724e3 100644 --- a/R/gisco_get_healthcare.R +++ b/R/gisco_get_healthcare.R @@ -26,7 +26,13 @@ #' \donttest{ #' #' health_BEL <- gisco_get_healthcare(country = "Belgium") -#' health_BEL +#' +#' # Plot if downloaded +#' if (nrow(edu_BEL) > 3) { +#' library(ggplot2) +#' ggplot(health_BEL) + +#' geom_sf(aes(color = emergency)) +#' } #' } #' @export gisco_get_healthcare <- function(cache = TRUE, update_cache = FALSE, diff --git a/README.Rmd b/README.Rmd index 5bedd227..4b982a53 100644 --- a/README.Rmd +++ b/README.Rmd @@ -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) diff --git a/README.md b/README.md index 1a615b66..410f1b38 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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: diff --git a/codemeta.json b/codemeta.json index 2b88c154..34063d23 100644 --- a/codemeta.json +++ b/codemeta.json @@ -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", @@ -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" } diff --git a/man/gisco_get.Rd b/man/gisco_get.Rd index 236630c7..8481a6c5 100644 --- a/man/gisco_get.Rd +++ b/man/gisco_get.Rd @@ -68,7 +68,7 @@ when \code{spatialtype} is \code{"BN"} or \code{"RG"}.} \item{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 \code{c("Turkey","US","FRA")}) +vector of Eurostat country codes. Mixed types (as \code{c("Italy","ES","FRA")}) would not work. See also \code{\link[countrycode:countrycode]{countrycode::countrycode()}}.} \item{region}{Optional. A character vector of UN M49 region codes or diff --git a/man/gisco_get_airports.Rd b/man/gisco_get_airports.Rd index f316b4db..ee49270c 100644 --- a/man/gisco_get_airports.Rd +++ b/man/gisco_get_airports.Rd @@ -29,7 +29,7 @@ gisco_get_ports( \item{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 \code{c("Turkey","US","FRA")}) +vector of Eurostat country codes. Mixed types (as \code{c("Italy","ES","FRA")}) would not work. See also \code{\link[countrycode:countrycode]{countrycode::countrycode()}}.} \item{cache_dir}{A path to a cache directory. See \strong{About caching}.} @@ -125,6 +125,7 @@ ggplot(coast) + } \seealso{ Other infrastructure: +\code{\link{gisco_get_education}()}, \code{\link{gisco_get_healthcare}()} } \concept{infrastructure} diff --git a/man/gisco_get_education.Rd b/man/gisco_get_education.Rd new file mode 100644 index 00000000..a04ab1d1 --- /dev/null +++ b/man/gisco_get_education.Rd @@ -0,0 +1,84 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gisco_get_education.R +\name{gisco_get_education} +\alias{gisco_get_education} +\title{Get locations of education services in Europe} +\source{ +\url{https://ec.europa.eu/eurostat/web/gisco/geodata/basic-services} +} +\usage{ +gisco_get_education( + cache = TRUE, + update_cache = FALSE, + cache_dir = NULL, + verbose = FALSE, + country = NULL +) +} +\arguments{ +\item{cache}{A logical whether to do caching. Default is \code{TRUE}. See +\strong{About caching}.} + +\item{update_cache}{A logical whether to update cache. Default is \code{FALSE}. +When set to \code{TRUE} it would force a fresh download of the source +\code{.geojson} file.} + +\item{cache_dir}{A path to a cache directory. See \strong{About caching}.} + +\item{verbose}{Logical, displays information. Useful for debugging, +default is \code{FALSE}.} + +\item{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 \code{c("Italy","ES","FRA")}) +would not work. See also \code{\link[countrycode:countrycode]{countrycode::countrycode()}}.} +} +\value{ +A \code{POINT} \code{\link[sf:sf]{sf}} object. +} +\description{ +The dataset contains information on main education services by Member States. +} +\details{ +Files are distributed on EPSG:4326. Metadata available on +\url{https://gisco-services.ec.europa.eu/pub/education/metadata.pdf}. +} +\section{About caching}{ +You can set your \code{cache_dir} with \code{\link[=gisco_set_cache_dir]{gisco_set_cache_dir()}}. + +Sometimes cached files may be corrupt. On that case, try re-downloading +the data setting \code{update_cache = TRUE}. + +If you experience any problem on download, try to download the +corresponding \code{.geojson} file by any other method and save it on your +\code{cache_dir}. Use the option \code{verbose = TRUE} for debugging the API query. + +For a complete list of files available check \link{gisco_db}. +} + +\examples{ +\dontshow{if (gisco_check_access()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\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) +} +} +\dontshow{\}) # examplesIf} +} +\seealso{ +\code{\link[=gisco_get_countries]{gisco_get_countries()}} + +Other infrastructure: +\code{\link{gisco_get_airports}()}, +\code{\link{gisco_get_healthcare}()} +} +\author{ +dieghernan, \url{https://github.com/dieghernan/} +} +\concept{infrastructure} diff --git a/man/gisco_get_healthcare.Rd b/man/gisco_get_healthcare.Rd index fa0b14e9..bdec0391 100644 --- a/man/gisco_get_healthcare.Rd +++ b/man/gisco_get_healthcare.Rd @@ -30,7 +30,7 @@ default is \code{FALSE}.} \item{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 \code{c("Turkey","US","FRA")}) +vector of Eurostat country codes. Mixed types (as \code{c("Italy","ES","FRA")}) would not work. See also \code{\link[countrycode:countrycode]{countrycode::countrycode()}}.} } \value{ @@ -62,7 +62,13 @@ For a complete list of files available check \link{gisco_db}. \donttest{ health_BEL <- gisco_get_healthcare(country = "Belgium") -health_BEL + +# Plot if downloaded +if (nrow(edu_BEL) > 3) { + library(ggplot2) + ggplot(health_BEL) + + geom_sf(aes(color = emergency)) +} } \dontshow{\}) # examplesIf} } @@ -70,7 +76,8 @@ health_BEL \code{\link[=gisco_get_countries]{gisco_get_countries()}} Other infrastructure: -\code{\link{gisco_get_airports}()} +\code{\link{gisco_get_airports}()}, +\code{\link{gisco_get_education}()} } \author{ dieghernan, \url{https://github.com/dieghernan/} diff --git a/man/gisco_get_lau.Rd b/man/gisco_get_lau.Rd index ac37ab9f..55ddea4c 100644 --- a/man/gisco_get_lau.Rd +++ b/man/gisco_get_lau.Rd @@ -69,7 +69,7 @@ when \code{spatialtype} is \code{"BN"} or \code{"RG"}.} \item{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 \code{c("Turkey","US","FRA")}) +vector of Eurostat country codes. Mixed types (as \code{c("Italy","ES","FRA")}) would not work. See also \code{\link[countrycode:countrycode]{countrycode::countrycode()}}.} \item{gisco_id}{Optional. A character vector of GISCO_ID LAU values.} diff --git a/man/gisco_get_nuts.Rd b/man/gisco_get_nuts.Rd index 81e59f82..480553c1 100644 --- a/man/gisco_get_nuts.Rd +++ b/man/gisco_get_nuts.Rd @@ -67,7 +67,7 @@ applied when \code{spatialtype} is \code{"BN"} or \code{"RG"}.} \item{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 \code{c("Turkey","US","FRA")}) +vector of Eurostat country codes. Mixed types (as \code{c("Italy","ES","FRA")}) would not work. See also \code{\link[countrycode:countrycode]{countrycode::countrycode()}}.} \item{nuts_id}{Optional. A character vector of NUTS IDs.} diff --git a/man/gisco_get_postalcodes.Rd b/man/gisco_get_postalcodes.Rd index ceb4eac7..126eb448 100644 --- a/man/gisco_get_postalcodes.Rd +++ b/man/gisco_get_postalcodes.Rd @@ -20,7 +20,7 @@ gisco_get_postalcodes( \item{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 \code{c("Turkey","US","FRA")}) +vector of Eurostat country codes. Mixed types (as \code{c("Italy","ES","FRA")}) would not work. See also \code{\link[countrycode:countrycode]{countrycode::countrycode()}}.} \item{cache_dir}{A path to a cache directory. See \strong{About caching}.} diff --git a/man/gisco_get_urban_audit.Rd b/man/gisco_get_urban_audit.Rd index 7e8054f3..553bd54e 100644 --- a/man/gisco_get_urban_audit.Rd +++ b/man/gisco_get_urban_audit.Rd @@ -52,7 +52,7 @@ default is \code{FALSE}.} \item{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 \code{c("Turkey","US","FRA")}) +vector of Eurostat country codes. Mixed types (as \code{c("Italy","ES","FRA")}) would not work. See also \code{\link[countrycode:countrycode]{countrycode::countrycode()}}.} \item{level}{Level of Urban Audit. Possible values are \code{"CITIES"}, \code{"FUA"}, diff --git a/tests/testthat/test-gisco_get_education.R b/tests/testthat/test-gisco_get_education.R new file mode 100644 index 00000000..87a9e4aa --- /dev/null +++ b/tests/testthat/test-gisco_get_education.R @@ -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) +}) diff --git a/tests/testthat/test-gisco_get_urban_audit.R b/tests/testthat/test-gisco_get_urban_audit.R index 17f2af1c..f801eaa5 100644 --- a/tests/testthat/test-gisco_get_urban_audit.R +++ b/tests/testthat/test-gisco_get_urban_audit.R @@ -10,9 +10,9 @@ test_that("Urban Audit online", { skip_on_cran() skip_if_gisco_offline() - expect_silent(gisco_get_urban_audit(level = "GREATER_CITIES")) + expect_silent(gisco_get_urban_audit(level = "CITIES")) fromurl <- expect_silent(gisco_get_urban_audit( - level = "GREATER_CITIES", + level = "CITIES", cache = FALSE )) @@ -36,6 +36,7 @@ test_that("Urban Audit online", { gisco_get_urban_audit( level = "GREATER_CITIES", spatialtype = "LB", + year = 2020, epsg = 3857, country = c("ITA", "POL") ) diff --git a/vignettes/giscoR.Rmd b/vignettes/giscoR.Rmd index beeb6234..2b23c77f 100644 --- a/vignettes/giscoR.Rmd +++ b/vignettes/giscoR.Rmd @@ -189,7 +189,7 @@ eu_bord <- borders %>% # Eurostat data - Disposable income pps <- get_eurostat("tgs00026") %>% filter(TIME_PERIOD == "2021-01-01") -#> indexed 0B in 0s, 0B/s indexed 1.00TB in 0s, 4.35PB/s +#> indexed 0B in 0s, 0B/s indexed 1.00TB in 0s, 4.79PB/s ``` ``` r