From 633af42aee20fcd3076d6953aab014801a699cac Mon Sep 17 00:00:00 2001 From: Sebastian Gatscha Date: Sun, 1 Sep 2024 21:32:36 +0200 Subject: [PATCH] add examples --- R/heightgraph.R | 10 ++++------ R/labelgun.R | 11 +++++++++++ R/movingmarker.R | 3 +-- R/timeslider.R | 3 +-- man/addHeightgraph.Rd | 9 +++------ man/addLabelgun.Rd | 12 ++++++++++++ man/addMovingMarker.Rd | 2 -- man/addTimeslider.Rd | 2 -- 8 files changed, 32 insertions(+), 20 deletions(-) diff --git a/R/heightgraph.R b/R/heightgraph.R index 1ebe8d86..325dbfd9 100644 --- a/R/heightgraph.R +++ b/R/heightgraph.R @@ -40,7 +40,7 @@ heightgraphDependency <- function() { #' @family Heightgraph Functions #' @inherit leaflet::addGeoJSON return #' @export -#' @examples \dontrun{ +#' @examples #' library(leaflet) #' library(leaflet.extras2) #' library(sf) @@ -48,17 +48,16 @@ heightgraphDependency <- function() { #' data <- st_cast(st_as_sf(leaflet::atlStorms2005[4,]), "LINESTRING") #' data <- st_transform(data, 4326) #' data <- data.frame(st_coordinates(data)) -#' data$elev <- runif(nrow(data), 10, 500) +#' data$elev <- round(runif(nrow(data), 10, 500), 2) #' data$L1 <- NULL #' L1 <- round(seq.int(1, 4, length.out = nrow(data))) -#' data <- st_as_sf(st_sfc(lapply(split(data, L1), sfg_linestring))) #' data <- st_as_sf(st_sfc(lapply(split(data, L1), function(x) { -#' st_linestring(as.matrix(x)) +#' st_linestring(as.matrix(x)) #' }))) #' data$steepness <- 1:nrow(data) #' data$suitability <- nrow(data):1 #' data$popup <- apply(data, 1, function(x) { -#' sprintf("Steepness: %s
Suitability: %s", x$steepness, x$suitability) +#' sprintf("Steepness: %s
Suitability: %s", x$steepness, x$suitability) #' }) #' #' leaflet() %>% @@ -66,7 +65,6 @@ heightgraphDependency <- function() { #' addHeightgraph(color = "red", columns = c("steepness", "suitability"), #' opacity = 1, data = data, group = "heightgraph", #' options = heightgraphOptions(width = 400)) -#' } addHeightgraph <- function( map, data = NULL, columns = NULL, layerId = NULL, group = NULL, color = "#03F", weight = 5, opacity = 0.5, diff --git a/R/labelgun.R b/R/labelgun.R index c201fdf4..82852fe8 100644 --- a/R/labelgun.R +++ b/R/labelgun.R @@ -38,6 +38,17 @@ labelgunDependency <- function() { #' @references \url{https://github.com/Geovation/labelgun} #' #' @name addLabelgun +#' @examples +#' library(leaflet) +#' library(leaflet.extras2) +#' +#' leaflet() %>% +#' addTiles() %>% +#' addMarkers(data = breweries91, +#' label = ~brewery, +#' group = "markers", +#' labelOptions = labelOptions(permanent = TRUE)) %>% +#' addLabelgun("markers", 1) addLabelgun <- function(map, group=NULL, weight=NULL, entries=NULL) { stopifnot("The group argument is NULL. Please define a valid group." = !is.null(group)) map$dependencies <- c(map$dependencies, labelgunDependency()) diff --git a/R/movingmarker.R b/R/movingmarker.R index 4afe66e0..2ba390ad 100644 --- a/R/movingmarker.R +++ b/R/movingmarker.R @@ -36,7 +36,7 @@ leafletAwesomeMarkersDependencies1 <- function() { #' @references \url{https://github.com/ewoken/Leaflet.MovingMarker} #' @inherit leaflet::addMarkers return #' @export -#' @examples \dontrun{ +#' @examples #' library(sf) #' library(leaflet) #' library(leaflet.extras2) @@ -55,7 +55,6 @@ leafletAwesomeMarkersDependencies1 <- function() { #' movingOptions = movingMarkerOptions(autostart = TRUE, loop = TRUE), #' label="I am a pirate!", #' popup="Arrr") -#' } addMovingMarker = function( map, lng = NULL, lat = NULL, layerId = NULL, group = NULL, duration = 2000, diff --git a/R/timeslider.R b/R/timeslider.R index 7cae497d..09d9a9e3 100644 --- a/R/timeslider.R +++ b/R/timeslider.R @@ -29,7 +29,7 @@ timesliderDependencies <- function() { #' @export #' @inheritParams leaflet::addCircleMarkers #' @inherit leaflet::addMarkers return -#' @examples \dontrun{ +#' @examples #' library(leaflet) #' library(leaflet.extras2) #' library(sf) @@ -47,7 +47,6 @@ timesliderDependencies <- function() { #' timeAttribute = "time", #' range = TRUE)) %>% #' setView(-72, 22, 4) -#' } addTimeslider <- function(map, data, radius = 10, stroke = TRUE, color = "#03F", weight = 5, opacity = 0.5, fill = TRUE, fillColor = color, diff --git a/man/addHeightgraph.Rd b/man/addHeightgraph.Rd index 4a483cfc..866aeb3b 100644 --- a/man/addHeightgraph.Rd +++ b/man/addHeightgraph.Rd @@ -77,7 +77,6 @@ If you want to explicitly remove the Heightgraph control, please use \code{\link[leaflet]{removeControl}} with the \code{layerId = "hg_control"}. } \examples{ -\dontrun{ library(leaflet) library(leaflet.extras2) library(sf) @@ -85,17 +84,16 @@ library(sf) data <- st_cast(st_as_sf(leaflet::atlStorms2005[4,]), "LINESTRING") data <- st_transform(data, 4326) data <- data.frame(st_coordinates(data)) -data$elev <- runif(nrow(data), 10, 500) +data$elev <- round(runif(nrow(data), 10, 500), 2) data$L1 <- NULL L1 <- round(seq.int(1, 4, length.out = nrow(data))) -data <- st_as_sf(st_sfc(lapply(split(data, L1), sfg_linestring))) data <- st_as_sf(st_sfc(lapply(split(data, L1), function(x) { - st_linestring(as.matrix(x)) + st_linestring(as.matrix(x)) }))) data$steepness <- 1:nrow(data) data$suitability <- nrow(data):1 data$popup <- apply(data, 1, function(x) { - sprintf("Steepness: \%s
Suitability: \%s", x$steepness, x$suitability) + sprintf("Steepness: \%s
Suitability: \%s", x$steepness, x$suitability) }) leaflet() \%>\% @@ -104,7 +102,6 @@ leaflet() \%>\% opacity = 1, data = data, group = "heightgraph", options = heightgraphOptions(width = 400)) } -} \references{ \url{https://github.com/GIScience/Leaflet.Heightgraph} } diff --git a/man/addLabelgun.Rd b/man/addLabelgun.Rd index 69209ed3..4fbb9b58 100644 --- a/man/addLabelgun.Rd +++ b/man/addLabelgun.Rd @@ -34,6 +34,18 @@ to labels of your choice (with higher weight). It is important to invoke the function after the markers have been added to the map. Otherwise nothing will happen. } +\examples{ +library(leaflet) +library(leaflet.extras2) + +leaflet() \%>\% + addTiles() \%>\% + addMarkers(data = breweries91, + label = ~brewery, + group = "markers", + labelOptions = labelOptions(permanent = TRUE)) \%>\% + addLabelgun("markers", 1) +} \references{ \url{https://github.com/Geovation/labelgun} } diff --git a/man/addMovingMarker.Rd b/man/addMovingMarker.Rd index 93094e81..37bb5a1b 100644 --- a/man/addMovingMarker.Rd +++ b/man/addMovingMarker.Rd @@ -78,7 +78,6 @@ The function expects either line or point data as spatial data or as Simple Feat Alternatively, coordinates can also be passed as numeric vectors. } \examples{ -\dontrun{ library(sf) library(leaflet) library(leaflet.extras2) @@ -98,7 +97,6 @@ leaflet() \%>\% label="I am a pirate!", popup="Arrr") } -} \references{ \url{https://github.com/ewoken/Leaflet.MovingMarker} } diff --git a/man/addTimeslider.Rd b/man/addTimeslider.Rd index 64a99d36..05d4497d 100644 --- a/man/addTimeslider.Rd +++ b/man/addTimeslider.Rd @@ -80,7 +80,6 @@ enables you to dynamically add and remove Markers/Lines on a map by using a JQuery UI slider. } \examples{ -\dontrun{ library(leaflet) library(leaflet.extras2) library(sf) @@ -99,7 +98,6 @@ leaflet() \%>\% range = TRUE)) \%>\% setView(-72, 22, 4) } -} \references{ \url{https://github.com/dwilhelm89/LeafletSlider} }