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

docs: Replace {sp} with {sf} in pkgdown site; Fix a handful of broken examples #928

Merged
merged 10 commits into from
Aug 7, 2024
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Suggests:
terra,
testthat (>= 3.0.0)
Config/testthat/edition: 3
Config/Needs/website: dplyr, geojsonio, ncdf4, tidyverse/tidytemplate
Config/Needs/website: dplyr, ncdf4, rnaturalearth, tidyverse/tidytemplate
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# leaflet (development version)

* Color palette improvements. All color palette functions now support all `{viridisLite}` palettes ("magma", "inferno", "plasma", "viridis", "cividis", "rocket", "mako", and "turbo").
* Color palette improvements. All color palette functions now support all `{viridisLite}` palettes ("magma", "inferno", "plasma", "viridis", "cividis", "rocket", "mako", and "turbo") (@jack-davison, #924).
schloerke marked this conversation as resolved.
Show resolved Hide resolved
schloerke marked this conversation as resolved.
Show resolved Hide resolved

* Updated vignettes to replace `{sp}`/`{raster}` usage with `{sf}`/`{terra}` and their corresponding examples. (@jack-davison, #928)

* Updated vignettes to replace `{sp}`/`{raster}` usage with `{sf}`/`{terra} and their corresponding examples. (@jack-davison, #928)

# leaflet 2.2.2

Expand Down
8 changes: 4 additions & 4 deletions R/colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @param domain The possible values that can be mapped.
#'
#' For `colorNumeric()` and `colorBin()`, this can be a simple numeric
#' range (e.g. `c(0, 100)`); `colorQuantile()` needs representative
#' range (e.g., `c(0, 100)`); `colorQuantile()` needs representative
schloerke marked this conversation as resolved.
Show resolved Hide resolved
#' numeric data; and `colorFactor()` needs categorical data.
#'
#' If `NULL`, then whenever the resulting color function is called, the
Expand Down Expand Up @@ -250,7 +250,7 @@ colorFactor <- function(palette, domain, levels = NULL, ordered = FALSE,
#' @details The `palette` argument can be any of the following:
#' \enumerate{
#' \item{A character vector of RGB or named colors. Examples: `palette()`, `c("#000000", "#0000FF", "#FFFFFF")`, `topo.colors(10)`}
#' \item{The name of an RColorBrewer palette, e.g. `"BuPu"` or `"Greens"`.}
#' \item{The name of an RColorBrewer palette, e.g., `"BuPu"` or `"Greens"`.}
#' \item{The full name of a viridis palette: `"magma"`, `"inferno"`, `"plasma"`, `"viridis"`, `"cividis"`, `"rocket"`, `"mako"`, or `"turbo"`}
#' \item{A function that receives a single value between 0 and 1 and returns a color. Examples: `colorRamp(c("#000000", "#FFFFFF"), interpolate = "spline")`.}
#' }
Expand Down Expand Up @@ -287,8 +287,8 @@ safePaletteFunc <- function(pal, na.color, alpha, nlevels = NULL) {
}

# nlevels is a positive or negative integer (or integral number) indicating the
# number of levels to use for a discrete scale (i.e. factor, i.e. qualitative,
# i.e. categorical); or NULL if it is a continuous scale. A negative value means
# number of levels to use for a discrete scale (i.e., factor, i.e., qualitative,
# i.e., categorical); or NULL if it is a continuous scale. A negative value means
# that the user has asked for a "reversed" palette, so pull from the tail of the
# color palette rather than from the head.
#
Expand Down
16 changes: 8 additions & 8 deletions R/layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ evalFormula <- function(list, data) {
# least they are the same shape as the Spatial bounding boxes).

#' Notifies the map of new latitude/longitude of items of interest on the map
# So that we can expand the limits (i.e. bounding box). We will use this as the
# So that we can expand the limits (i.e., bounding box). We will use this as the
# initial view if the user doesn't explicitly specify bounds using fitBounds.
#' @param map map object
#' @param lat vector of latitudes
Expand Down Expand Up @@ -624,7 +624,7 @@ clearImages <- function(map) {
#' minZoom,maxZoom,maxNativeZoom,tileSize,subdomains,errorTileUrl,tms,noWrap,zoomOffset,zoomReverse,zIndex,unloadInvisibleTiles,updateWhenIdle,detectRetina
#' the tile layer options; see
#' <https://web.archive.org/web/20220702182250/https://leafletjs.com/reference-1.3.4.html#tilelayer>
#' @param ... extra options passed to underlying Javascript object constructor.
#' @param ... extra options passed to underlying JavaScript object constructor.
#' @describeIn map-options Options for tile layers
#' @export
tileOptions <- function(
Expand Down Expand Up @@ -765,7 +765,7 @@ WMSTileOptions <- function(
#' (for [clearGroup()] and [addLayersControl()] purposes).
#' 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.
#' layers (e.g., markers and polygons) can share the same group name.
#' @template data-getMapData
#' @describeIn map-layers Add popups to the map
#' @export
Expand Down Expand Up @@ -924,7 +924,7 @@ addMarkers <- function(

if (!is.null(icon)) {
# If custom icons are specified, we need to 1) deduplicate any URLs/files,
# so we can efficiently send e.g. 1000 markers that all use the same 2
# so we can efficiently send e.g., 1000 markers that all use the same 2
# icons; and 2) do base64 encoding on any local icon files (as opposed to
# URLs [absolute or relative] which will be left alone).

Expand Down Expand Up @@ -1113,7 +1113,7 @@ makeIcon <- function(iconUrl = NULL, iconRetinaUrl = NULL, iconWidth = NULL, ico
#' icon image
#' @param iconWidth,iconHeight size of the icon image in pixels
#' @param iconAnchorX,iconAnchorY the coordinates of the "tip" of the icon
#' (relative to its top left corner, i.e. the top left corner means
#' (relative to its top left corner, i.e., the top left corner means
#' `iconAnchorX = 0` and `iconAnchorY = 0`), and the icon will be
#' aligned so that this point is at the marker's geographical location
#' @param shadowUrl the URL or file path to the icon shadow image
Expand Down Expand Up @@ -1216,7 +1216,7 @@ markerOptions <- function(
#' to style spider legs. By default, they are
#' \code{\{weight: 1.5, color: "#222", opacity: 0.5 \}}.
#' @param freezeAtZoom Allows you to freeze cluster expansion to a zoom level.
#' Can be a zoom level e.g. 10, 12 or "max" or "maxKeepSpiderify".
#' Can be a zoom level e.g., 10, 12 or "max" or "maxKeepSpiderify".
#' See <https://github.com/ghybs/Leaflet.MarkerCluster.Freezable#api-reference>.
#' @describeIn map-options Options for marker clusters
#' @export
Expand All @@ -1240,12 +1240,12 @@ markerClusterOptions <- function(
#' @param radius a numeric vector of radii for the circles; it can also be a
#' one-sided formula, in which case the radius values are derived from the
#' `data` (units in meters for circles, and pixels for circle markers)
#' @param stroke whether to draw stroke along the path (e.g. the borders of
#' @param stroke whether to draw stroke along the path (e.g., the borders of
#' polygons or circles)
#' @param color stroke color
#' @param weight stroke width in pixels
#' @param opacity stroke opacity (or layer opacity for tile layers)
#' @param fill whether to fill the path with color (e.g. filling on polygons or
#' @param fill whether to fill the path with color (e.g., filling on polygons or
#' circles)
#' @param fillColor fill color
#' @param fillOpacity fill opacity
Expand Down
4 changes: 2 additions & 2 deletions R/legend.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Add a color legend to a map
#'
#' When a color palette function is used in a map (e.g.
#' When a color palette function is used in a map (e.g.,
#' [colorNumeric()]), a color legend can be automatically derived from
#' the palette function. You can also manually specify the colors and labels for
#' the legend.
Expand Down Expand Up @@ -54,7 +54,7 @@
#' with this name and will auto add/remove the legend as the
#' group is added/removed, for example via `layerControl()`.
#' You will need to set the `group` when you add a layer
#' (e.g. [addPolygons()]) and supply the same name here.
#' (e.g., [addPolygons()]) and supply the same name here.
#' @template data-getMapData
#' @example inst/examples/legend.R
#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/mapPane.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' overlay pane) and 500 (the default shadow pane). You can then use this pane
#' to render overlays (points, lines, polygons) by setting the `pane`
#' argument in [leafletOptions()]. This will give you control
#' over the order of the layers, e.g. points always on top of polygons.
#' over the order of the layers, e.g., points always on top of polygons.
#' If two layers are provided to the same pane, overlay will be determined by
#' order of adding. See examples below.
#' See <https://web.archive.org/web/20220702182250/https://leafletjs.com/reference-1.3.4.html#map-pane> for details.
Expand Down
2 changes: 1 addition & 1 deletion R/normalize.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ checkMatrix <- function(x) {
# - to_ring
#
# Each of the specific sp/sf classes need only implement whichever ONE of those
# actually makes sense (e.g. to_multipolygon_list.sfc,
# actually makes sense (e.g., to_multipolygon_list.sfc,
# to_multipolygon.MULTIPOLYGON, to_polygon.POLYGON, to_ring.LINESTRING). The
# higher-level polygonData wrappers will simply call to_multipolygon_list(x),
# and the default implementations of those methods will fall through to the next
Expand Down
2 changes: 1 addition & 1 deletion R/plugin-awesomeMarkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ verifyIconLibrary <- function(library) {
#' (for [clearGroup()] and [addLayersControl()] purposes).
#' 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.
#' layers (e.g., markers and polygons) can share the same group name.
#' @param data the data object from which the argument values are derived; by
#' default, it is the `data` object provided to `leaflet()`
#' initially, but can be overridden
Expand Down
2 changes: 1 addition & 1 deletion R/plugin-terminator.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ leafletTerminatorDependencies <- function() {
#'
#' @param map a map widget object
#' @param resolution the step size at which the terminator points are computed.
#' The step size is 1 degree/resolution, i.e. higher resolution values have
#' The step size is 1 degree/resolution, i.e., higher resolution values have
#' smaller step sizes and more points in the polygon. The default value is 2.
#' @param time Time
#' @param layerId the layer id
Expand Down
2 changes: 1 addition & 1 deletion man/addAwesomeMarkers.Rd

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

4 changes: 2 additions & 2 deletions man/addLegend.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/addMapPane.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/addTerminator.Rd

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

4 changes: 2 additions & 2 deletions man/colorNumeric.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/icons.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/makeIcon.Rd

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

6 changes: 3 additions & 3 deletions man/map-layers.Rd

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

4 changes: 2 additions & 2 deletions man/map-options.Rd

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

11 changes: 5 additions & 6 deletions vignettes/articles/choropleths.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ library(magrittr)

```{r fig.height = 4.75, echo = FALSE, message = FALSE}
# From https://leafletjs.com/examples/choropleth/us-states.js
states <- geojsonio::geojson_read("https://rstudio.github.io/leaflet/json/us-states.geojson", what = "sp")
states <- sf::read_sf("https://rstudio.github.io/leaflet/json/us-states.geojson")

bins <- c(0, 10, 20, 50, 100, 200, 500, 1000, Inf)
pal <- colorBin("YlOrRd", domain = states$density, bins = bins)
Expand Down Expand Up @@ -61,16 +61,15 @@ leaflet(states) %>%

We'll start by loading the data from JSON. While the Leaflet.js example loads the JSON directly into JavaScript, with the Leaflet R package we instead want to load the data into R.

In this case, we'll use the `geojsonio` package to load the data into `sp` objects, which will let us easily manipulate the geographic features, and their properties, in R.
In this case, we'll use the `{sf}` package to load the data into an `sf` `data.frame`, which will let us easily manipulate the geographic features, and their properties, in R.

<!-- TODO Use sf everywhere? -->
```{r}
states <- geojsonio::geojson_read("https://rstudio.github.io/leaflet/json/us-states.geojson", what = "sp")
states <- sf::read_sf("https://rstudio.github.io/leaflet/json/us-states.geojson")
class(states)
names(states)
```

As you can see, we now have a `SpatialPolygonsDataFrame` with `name` (state name) and `density` (population density in people/mi<sup>2</sup>) columns from the GeoJSON.
As you can see, we now have an `sf` `data.frame` with `name` (state name) and `density` (population density in people/mi<sup>2</sup>) columns from the GeoJSON.

### Basic states map

Expand Down Expand Up @@ -187,7 +186,7 @@ m %>% addLegend(pal = pal, values = ~density, opacity = 0.7, title = NULL,

```{r results = 'hide'}
# From https://leafletjs.com/examples/choropleth/us-states.js
states <- geojsonio::geojson_read("https://rstudio.github.io/leaflet/json/us-states.geojson", what = "sp")
states <- sf::read_sf("https://rstudio.github.io/leaflet/json/us-states.geojson")

bins <- c(0, 10, 20, 50, 100, 200, 500, 1000, Inf)
pal <- colorBin("YlOrRd", domain = states$density, bins = bins)
Expand Down
Loading
Loading