Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review documentation #108

Merged
merged 5 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ VignetteBuilder:
Config/Needs/check: curl
Config/Needs/coverage: covr
Config/Needs/website: ragg, reactable, rnaturalearth, tidyverse,
ropenspain/rostemplate, ropensci/rnaturalearthhires, devtools
ropenspain/rostemplate, ropensci/rnaturalearthhires, devtools, remotes
Config/testthat/edition: 3
Config/testthat/parallel: true
Copyright: © EuroGeographics for the administrative boundaries. Atlas
Expand Down
41 changes: 8 additions & 33 deletions R/addProviderEspTiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ leafletprovidersESP_v <- "v1.3.3"
#' map
#'
#' @description
#' Include tiles of public Spanish organisms to a
#' [leaflet::leaflet()] map.
#' Include tiles of public Spanish organisms to a [leaflet::leaflet()] map.
#'
#' @family imagery utilities
#' @seealso [leaflet::leaflet()], [leaflet::addTiles()]
Expand All @@ -21,41 +20,23 @@ leafletprovidersESP_v <- "v1.3.3"
#'
#' @return A modified [leaflet::leaflet()] `map` object.
#'
#'
#'
#' @export
#'
#' @param map A map widget created from [leaflet::leaflet()].
#' @param group The name of the group the newly created layers should belong to
#' Human-friendly group names are permitted–they need not be short,
#' identifier-style names. Any number of layers and even different types of
#' layers (e.g. markers and polygons) can share the same group name. See
#' [leaflet::addTiles()].
#' @param provider Name of the provider, see [esp_tiles_providers] for
#' values available.
#' @param ... Arguments passed on to [leaflet::providerTileOptions()].
#' @inheritParams leaflet::addProviderTiles
#' @inheritParams leaflet::addTiles
#'
#' @examples
#' library(leaflet)
#' PuertadelSol <-
#' leaflet() %>%
#' setView(
#' lat = 40.4166,
#' lng = -3.7038400,
#' zoom = 18
#' ) %>%
#' PuertadelSol <- leaflet() %>%
#' setView(lat = 40.4166, lng = -3.7038400, zoom = 18) %>%
#' addProviderEspTiles(provider = "IGNBase.Gris") %>%
#' addProviderEspTiles(provider = "RedTransporte.Carreteras")
#'
#' PuertadelSol
addProviderEspTiles <- function(map, provider, layerId = NULL,
group = NULL,
addProviderEspTiles <- function(map, provider, layerId = NULL, group = NULL,
Dismissed Show dismissed Hide dismissed
Dismissed Show dismissed Hide dismissed
options = providerEspTileOptions()) {
if (!requireNamespace("leaflet", quietly = TRUE)) {
stop("leaflet package required for using this function")
}

# A. Check providers
prov_list <- mapSpain::esp_tiles_providers

Expand All @@ -64,8 +45,7 @@ addProviderEspTiles <- function(map, provider, layerId = NULL,

if (!provider %in% allprovs) {
stop(
"No match for provider = '",
provider,
"No match for provider = '", provider,
"' found.\n\nCheck available providers in mapSpain::esp_tiles_providers."
)
}
Expand Down Expand Up @@ -176,18 +156,13 @@ addProviderEspTiles <- function(map, provider, layerId = NULL,
#' @name providerEspTileOptions
#'
#' @details
#' [providerEspTileOptions()] is a wrapper of
#' [leaflet::providerTileOptions()].
#'
#' [providerEspTileOptions()] is a wrapper of [leaflet::providerTileOptions()].
#'
#' @param ... Arguments passed on to [leaflet::providerTileOptions()].
#' @seealso [leaflet::providerTileOptions()], [leaflet::tileOptions()]
#'
#' @export
providerEspTileOptions <- function(...) {
if (!requireNamespace("leaflet", quietly = TRUE)) {
stop("leaflet package required for using this function")
}

ops <- leaflet::providerTileOptions(...)
return(ops)
}
60 changes: 30 additions & 30 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Spanish Code Translation Data Frame
#' Database with codes and names of spanish regions
#'
#' @family datasets
#' @family political
Expand All @@ -9,21 +9,21 @@
#' @docType data
#'
#' @description
#' A data frame used internally for translating codes and names of the
#' different subdivisions of Spain. The data frame provides the hierarchy of
#' the subdivisions including NUTS1 level, Autonomous Communities
#' (equivalent to NUTS2), Provinces and NUTS3 level. See **Note**.
#' A `data.frame` object used internally for translating codes and names of the
#' different subdivisions of Spain. The `data.frame` provides the hierarchy of
#' the subdivisions including NUTS1 level, autonomous communities (equivalent
#' to NUTS2), provinces and NUTS3 level. See **Note**.
#'
#' @source
#' * **INE**: Instituto Nacional de Estadistica: <https://www.ine.es/>
#' * **Eurostat (NUTS)**: <https://ec.europa.eu/eurostat/web/nuts/overview>
#' * **ISO**: <https://www.iso.org/home.html>
#' * **CLDR**: <https://unicode-org.github.io/cldr-staging/charts/38/index.html>
#' - **INE**: Instituto Nacional de Estadistica: <https://www.ine.es/>
#' - **Eurostat (NUTS)**: <https://ec.europa.eu/eurostat/web/nuts/overview>
#' - **ISO**: <https://www.iso.org/home.html>
#' - **CLDR**: <https://unicode-org.github.io/cldr-staging/charts/38/index.html>
#'
#' @encoding UTF-8
#'
#' @format
#' A data frame with `r nrow(mapSpain::esp_codelist)` rows
#' A [`data.frame`][base::data.frame] with `r nrow(mapSpain::esp_codelist)` rows
#' codes and columns:
#'
#' \describe{
Expand Down Expand Up @@ -83,19 +83,19 @@
#' Although NUTS2 matches the first subdivision level of Spain
#' (CCAA - Autonomous Communities), it should be noted that NUTS3 does not
#' match the second subdivision level of Spain (Provinces). NUTS3 provides a
#' dedicated code for major islands whereas the Provinces doesn't.
#' dedicated code for major islands whereas the provinces doesn't.
#'
#' Ceuta and Melilla has an specific status (Autonomous Cities) but are
#' considered as communities with a single province (as Madrid, Asturias
#' or Murcia) on this dataset.
#' considered as autonomous communities with a single province (as Madrid,
#' Asturias or Murcia) on this database.
#'
#' @examples
#'
#' data("esp_codelist")
NULL


#' All NUTS `POLYGON` object of Spain
#' [`sf`][sf::st_sf] object with all the NUTS levels of Spain (2016)
#'
#' @family datasets
#' @family nuts
Expand All @@ -122,7 +122,7 @@ NULL
#' \item{LEVL_CODE}{NUTS level code (0,1,2,3)}
#' \item{NUTS_ID}{NUTS identifier}
#' \item{URBN_TYPE}{Urban Type, see Details}
#' \item{CNTR_CODE}{Eurostat Country code \code{ES}}
#' \item{CNTR_CODE}{Eurostat Country code `ES`}
#' \item{NAME_LATN}{NUTS name on Latin characters}
#' \item{NUTS_NAME}{NUTS name on local alphabet}
#' \item{MOUNT_TYPE}{Mount Type, see Details}
Expand Down Expand Up @@ -159,8 +159,7 @@ NULL
#'
NULL

#' All Municipalities `POLYGON` object of Spain (2019)
#'
#' [`sf`][sf::st_sf] object with all the municipalities of Spain (2019)
#' @family datasets
#' @family municipalities
#'
Expand All @@ -187,7 +186,7 @@ NULL
#'
#' @seealso [esp_get_munic()].
#' @format
#' A [`sf`][sf::st_sf] object (resolution: 1:1million, EPSG:4258) object with
#' A [`sf`][sf::st_sf] object (resolution: 1:1 million, EPSG:4258) object with
#' `r prettyNum(nrow(mapSpain::esp_munic.sf), big.mark=",")` rows and columns:
#' \describe{
#' \item{codauto}{INE code of the autonomous community.}
Expand All @@ -197,14 +196,15 @@ NULL
#' \item{cmun}{INE code of the municipality.}
#' \item{name}{Name of the municipality.}
#' \item{LAU_CODE}{LAU Code (GISCO) of the municipality. This is a
#' combination of **cpro** and **cmun**, aligned with INE coding scheme.}
#' combination of **cpro** and **cmun** fields, aligned with INE coding
#' scheme.}
#' \item{geometry}{geometry field.}
#' }
#' @example inst/examples/esp_munic_sf.R
NULL


#' @title Population by municipality (2019)
#' Database with the population of Spain by municipality (2019)
#'
#' @family datasets
#'
Expand All @@ -213,7 +213,7 @@ NULL
#' @docType data
#'
#' @format
#' An example data frame with
#' An example `data.frame` object with
#' `r prettyNum(nrow(mapSpain::pobmun19), big.mark=",")` rows containing the
#' population data by municipality in Spain (2019).
#'
Expand All @@ -234,7 +234,7 @@ NULL
NULL


#' @title Public WMS and WMTS of Spain
#' (Superseded) Database of public WMS and WMTS of Spain
#'
#' @keywords internal
#'
Expand All @@ -243,10 +243,10 @@ NULL
#' @description
#' `r lifecycle::badge('superseded')`
#'
#' This data frame is not longer in use by \CRANpkg{mapSpain}. See
#' This `data.frame` is not longer in use by \CRANpkg{mapSpain}. See
#' [esp_tiles_providers] instead.
#'
#' A data frame containing information of different public WMS and WMTS
#' A `data.frame` containing information of different public WMS and WMTS
#' providers of Spain
#'
#'
Expand All @@ -259,7 +259,7 @@ NULL
#' @encoding UTF-8
#'
#' @format
#' A data frame object with a list of the required parameters for calling
#' A `data.frame` object with a list of the required parameters for calling
#' the service:
#' \describe{
#' \item{provider}{Provider name}.
Expand All @@ -271,17 +271,17 @@ NULL
#' data("leaflet.providersESP.df")
NULL

#' @title List with information of Public WMS and WMTS of Spain
#' Database of public WMS and WMTS of Spain
#'
#' @family datasets
#' @family imagery utilities
#'
#' @name esp_tiles_providers
#'
#' @description
#' A named list of length `r length(esp_tiles_providers)` containing
#' the parameters of the url information of different public WMS and WMTS
#' providers of Spain.
#' A named [`list`][base::list] of length `r length(esp_tiles_providers)`
#' containing the parameters of the url information of different public WMS and
#' WMTSproviders of Spain.
#'
#' Implementation of javascript plugin
#' [leaflet-providersESP](https://dieghernan.github.io/leaflet-providersESP/)
Expand All @@ -296,7 +296,7 @@ NULL
#' @encoding UTF-8
#'
#' @format
#' A named list of the providers available with the following structure:
#' A named `list` of the providers available with the following structure:
#' - Each item of the list is named with the provider alias.
#' - Each element of the list contains two nested named lists:
#' - `static` with the parameters to get static tiles plus an additional item
Expand Down
39 changes: 19 additions & 20 deletions R/esp_cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,33 @@
#' @family cache utilities
#' @seealso [rappdirs::user_config_dir()]
#'
#' @return An (invisible) character with the path to your `cache_dir`.
#' @return
#' An (invisible) character with the path to your `cache_dir`.
#'
#' @description
#' This function will store your `cache_dir` path on your local machine and
#' would load it for future sessions. Type `Sys.getenv("MAPSPAIN_CACHE_DIR")` to
#' find your cached path.
#'
#' Alternatively, you can store the `cache_dir` manually with the following
#' options:
#' * Run `Sys.setenv(MAPSPAIN_CACHE_DIR = "cache_dir")`. You would need to
#' run this command on each session (Similar to `install = FALSE`).
#' * Set `options(mapSpain_cache_dir = "cache_dir")`. Similar to the previous
#' option. This is **not recommended any more**, and it is provided for
#' backwards compatibility purposes.
#' * Write this line on your .Renviron file:
#' `MAPSPAIN_CACHE_DIR = "value_for_cache_dir"` (same behavior than
#' `install = TRUE`). This would store your `cache_dir` permanently.
#' - Run `Sys.setenv(MAPSPAIN_CACHE_DIR = "cache_dir")`. You would need to
#' run this command on each session (Similar to `install = FALSE`).
#' - Set `options(mapSpain_cache_dir = "cache_dir")`. Similar to the previous
#' option. This is **not recommended any more**, and it is provided for
#' backwards compatibility purposes.
#' - Write this line on your .Renviron file:
#' `MAPSPAIN_CACHE_DIR = "value_for_cache_dir"` (same behavior than
#' `install = TRUE`). This would store your `cache_dir` permanently.
#'
#' @inheritParams esp_get_nuts
#' @param cache_dir A path to a cache directory. On missing value the function
#' would store the cached files on a temporary dir (See [base::tempdir()]).
#' @param install if `TRUE`, will install the key in your local machine for
#' use in future sessions. Defaults to `FALSE.` If `cache_dir` is `FALSE`
#' this parameter is set to `FALSE` automatically.
#' @param overwrite If this is set to `TRUE`, it will overwrite an existing
#' `MAPSPAIN_CACHE_DIR` that you already have in local machine.
#'
#' @param install Logical. If `TRUE`, will install the key in your local
#' machine for use in future sessions. Defaults to `FALSE.` If `cache_dir`
#' is `FALSE` this parameter is set to `FALSE` automatically.
#' @param overwrite Logical. If this is set to `TRUE`, it will overwrite an
#' existing `MAPSPAIN_CACHE_DIR` that you already have in local machine.
#'
#' @examples
#'
Expand All @@ -39,9 +40,7 @@
#'
#' Sys.getenv("MAPSPAIN_CACHE_DIR")
#' @export
esp_set_cache_dir <- function(cache_dir,
overwrite = FALSE,
install = FALSE,
esp_set_cache_dir <- function(cache_dir, overwrite = FALSE, install = FALSE,
verbose = TRUE) {
# Default if not provided
if (missing(cache_dir) || cache_dir == "") {
Expand Down Expand Up @@ -205,10 +204,10 @@ esp_hlp_cachedir <- function(cache_dir = NULL) {
#' @description
#'
#' Helper function to detect the current cache folder. See
#' [esp_set_cache_dir()]
#' [esp_set_cache_dir()].
#'
#'
#' @param x Ignored
#' @param x Ignored.
#'
#' @return A character with the path to your `cache_dir`.
#'
Expand Down
15 changes: 7 additions & 8 deletions R/esp_cache_clear.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
#' **Use this function with caution**. This function would clear your cached
#' data and configuration, specifically:
#'
#' * Deletes the \CRANpkg{mapSpain} config directory
#' - Deletes the \CRANpkg{mapSpain} config directory
#' (`rappdirs::user_config_dir("mapSpain", "R")`).
#' * Deletes the `cache_dir` directory.
#' * Deletes the values on stored on `Sys.getenv("MAPSPAIN_CACHE_DIR")` and
#' - Deletes the `cache_dir` directory.
#' - Deletes the values on stored on `Sys.getenv("MAPSPAIN_CACHE_DIR")` and
#' `options(mapSpain_cache_dir)`.
#'
#' @param config if `TRUE`, will delete the configuration folder of
#' @param config Logical. If `TRUE`, will delete the configuration folder of
#' \CRANpkg{mapSpain}.
#' @param cached_data If this is set to `TRUE`, it will delete your
#' `cache_dir` and all its content.
#' @param cached_data Logical. If `TRUE`, it will delete your `cache_dir` and
#' all its content.
#' @inheritParams esp_set_cache_dir
#'
#' @details
Expand All @@ -33,8 +33,7 @@
#'
#' Sys.getenv("MAPSPAIN_CACHE_DIR")
#' @export
esp_clear_cache <- function(config = FALSE,
cached_data = TRUE,
esp_clear_cache <- function(config = FALSE, cached_data = TRUE,
verbose = FALSE) {
config_dir <- rappdirs::user_config_dir("mapSpain", "R")
data_dir <- esp_hlp_detect_cache_dir()
Expand Down
Loading