Skip to content

Commit a6b1177

Browse files
committed
Exported some useful functions for use in external packages
1 parent abf6ded commit a6b1177

File tree

11 files changed

+199
-13
lines changed

11 files changed

+199
-13
lines changed

NAMESPACE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,15 @@ export(colorFactor)
5454
export(colorNumeric)
5555
export(colorQuantile)
5656
export(createLeafletMap)
57+
export(derivePoints)
58+
export(derivePolygons)
5759
export(dispatch)
5860
export(easyButton)
5961
export(easyButtonState)
62+
export(evalFormula)
63+
export(expandLimits)
64+
export(expandLimitsBbox)
65+
export(filterNULL)
6066
export(fitBounds)
6167
export(getMapData)
6268
export(hideGroup)
@@ -75,6 +81,7 @@ export(leafletProxy)
7581
export(makeAwesomeIcon)
7682
export(makeIcon)
7783
export(mapOptions)
84+
export(markerClusterDependencies)
7885
export(markerClusterOptions)
7986
export(markerOptions)
8087
export(pathOptions)
@@ -96,6 +103,7 @@ export(removeShape)
96103
export(removeTiles)
97104
export(removeTopoJSON)
98105
export(renderLeaflet)
106+
export(safeLabel)
99107
export(scaleBarOptions)
100108
export(setMaxBounds)
101109
export(setView)

R/layers.R

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
# Evaluate list members that are formulae, using the map data as the environment
2-
# (if provided, otherwise the formula environment)
1+
#' Evaluate list members that are formulae, using the map data as the environment
2+
#' (if provided, otherwise the formula environment)
3+
#' @param list with members as formulae
4+
#' @param data map data
5+
#' @export
36
evalFormula = function(list, data) {
47
evalAll = function(x) {
58
if (is.list(x)) {
@@ -15,9 +18,13 @@ evalFormula = function(list, data) {
1518
# polygon lists (returned from polygonData()) use `attr(x, "bbox")` (though at
1619
# least they are the same shape as the Spatial bounding boxes).
1720

18-
# Notifies the map of new latitude/longitude of items of interest on the map, so
19-
# that we can expand the limits (i.e. bounding box). We will use this as the
21+
#' Notifies the map of new latitude/longitude of items of interest on the map
22+
# So that we can expand the limits (i.e. bounding box). We will use this as the
2023
# initial view if the user doesn't explicitly specify bounds using fitBounds.
24+
#' @param map map object
25+
#' @param lat vector of latitudes
26+
#' @param lng vector of longitudes
27+
#' @export
2128
expandLimits = function(map, lat, lng) {
2229
if (is.null(map$x$limits)) map$x$limits = list()
2330

@@ -33,8 +40,11 @@ expandLimits = function(map, lat, lng) {
3340
map
3441
}
3542

36-
# Same as expandLimits, but takes a polygon (that presumably has a bbox attr)
37-
# rather than lat/lng.
43+
#' Same as expandLimits, but takes a polygon (that presumably has a bbox attr)
44+
#' rather than lat/lng.
45+
#' @param map map object
46+
#' @param poly A spatial object representing a polygon.
47+
#' @export
3848
expandLimitsBbox = function(map, poly) {
3949
bbox = attr(poly, "bbox", exact = TRUE)
4050
if (is.null(bbox)) stop("Polygon data had no bbox")
@@ -423,7 +433,9 @@ clearPopups = function(map) {
423433
invokeMethod(map, NULL, 'clearPopups')
424434
}
425435

426-
# Helper Function to create a safe label
436+
#' Helper Function to create a safe label
437+
#' @describeIn map-layers Create a label with sanitized text/html
438+
#' @export
427439
safeLabel <- function(label, data) {
428440
if (is.null(label)) {
429441
return(label)
@@ -553,6 +565,9 @@ addLabelOnlyMarkers = function(
553565
data = data)
554566
}
555567

568+
#' Adds marker-cluster-plugin HTML dependency
569+
#' @export
570+
#' @describeIn map-layers add maker cluster plugin
556571
markerClusterDependencies = function() {
557572
list(
558573
htmltools::htmlDependency(

R/normalize.R

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,16 @@ doResolveFormula.SpatialPointsDataFrame = function(data, f) {
5050
doResolveFormula(data@data, f)
5151
}
5252

53-
# Given a data object and lng/lat arguments (which may be NULL [meaning infer
54-
# from data], formula [which should be evaluated with respect to the data], or
55-
# vector data [which should be used as-is]) return a lng/lat data frame.
53+
#' Given a data object and lng/lat arguments (which may be NULL [meaning infer
54+
#' from data], formula [which should be evaluated with respect to the data], or
55+
#' vector data [which should be used as-is]) return a lng/lat data frame.
56+
#' @param data map data
57+
#' @param lng longitude
58+
#' @param lat latitude
59+
#' @param missingLng whether lng is missing
60+
#' @param missingLat whether lat is missing
61+
#' @param funcName Name of calling function (for logging)
62+
#' @export
5663
derivePoints = function(data, lng, lat, missingLng, missingLat, funcName) {
5764
if (missingLng || missingLat) {
5865
if (is.null(data)) {
@@ -78,6 +85,16 @@ derivePoints = function(data, lng, lat, missingLng, missingLat, funcName) {
7885
data.frame(lng = lng, lat = lat)
7986
}
8087

88+
#' Given a data object and lng/lat arguments (which may be NULL [meaning infer
89+
#' from data], formula [which should be evaluated with respect to the data], or
90+
#' vector data [which should be used as-is]) return a spatial object
91+
#' @param data map data
92+
#' @param lng longitude
93+
#' @param lat latitude
94+
#' @param missingLng whether lng is missing
95+
#' @param missingLat whether lat is missing
96+
#' @param funcName Name of calling function (for logging)
97+
#' @export
8198
derivePolygons = function(data, lng, lat, missingLng, missingLat, funcName) {
8299
if (missingLng != missingLat) {
83100
stop(funcName, " must be called with both lng and lat, or with neither.")

R/utils.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ dispatch = function(map,
3131
stop("Invalid map parameter")
3232
}
3333

34-
# remove NULL elements from a list
34+
#' remove NULL elements from a list
35+
#' @param x A list whose NULL elements will be filtered
36+
#' @export
3537
filterNULL = function(x) {
3638
if (length(x) == 0 || !is.list(x)) return(x)
3739
x[!unlist(lapply(x, is.null))]

man/derivePoints.Rd

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/derivePolygons.Rd

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/evalFormula.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/expandLimits.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/expandLimitsBbox.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/filterNULL.Rd

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)