From 3cf87ae5e37a35a3ed6d7fea4e556662c7e35cd4 Mon Sep 17 00:00:00 2001 From: olivroy Date: Mon, 5 Feb 2024 09:00:25 -0500 Subject: [PATCH] Use magrittr pipe for 4.0 compatibility --- R/tmapGridInit.R | 14 +++++++------- R/tmapLeafletComp.R | 8 ++++---- R/tmapLeafletLegend.R | 6 +++--- R/tmapLeafletShape.R | 6 +++--- R/tmapLeaflet_layers.R | 38 +++++++++++++++++++------------------- R/tmapShape.R | 2 +- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/R/tmapGridInit.R b/R/tmapGridInit.R index bfbac8d9..01784c0a 100644 --- a/R/tmapGridInit.R +++ b/R/tmapGridInit.R @@ -181,19 +181,19 @@ tmapGridInit = function(o, return.asp = FALSE, vp) { p = rep(cols4all::c4a("brewer.paired"), 3) - gt = gt |> - add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[1])), row = 1:(nr), col = 1:(nc)) |> # outer - add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[2])), row = 2:(nr-1), col = 2:(nc-1)) |> # meta buffer out - add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[3])), row = 3:(nr-2), col = 3:(nc-2)) |> # meta margins - add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[2])), row = 4:(nr-3), col = 4:(nc-3)) |> # meta buffer in + gt = gt %>% + add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[1])), row = 1:(nr), col = 1:(nc)) %>% # outer + add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[2])), row = 2:(nr-1), col = 2:(nc-1)) %>% # meta buffer out + add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[3])), row = 3:(nr-2), col = 3:(nc-2)) %>% # meta margins + add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[2])), row = 4:(nr-3), col = 4:(nc-3)) %>% # meta buffer in add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[4])), row = 5:(nr-4), col = 5:(nc-4)) # xylab if (o$panel.type == "xtab") { #add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[5])), row = 6:(nr-5), col = 6:(nc-5)) # panel buffer gt = add_to_gt(gt, grid::rectGrob(gp=grid::gpar(fill = p[5])), row = 6:(nr-5), col = 6:(nc-5)) # panel } - gt = gt |> - add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[6])), row = 7:(nr-6), col = 7:(nc-6)) |> # grid buffer + gt = gt %>% + add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[6])), row = 7:(nr-6), col = 7:(nc-6)) %>% # grid buffer add_to_gt(grid::rectGrob(gp=grid::gpar(fill = p[7])), row = 8:(nr-7), col = 8:(nc-7)) # grid diff --git a/R/tmapLeafletComp.R b/R/tmapLeafletComp.R index a3d155b4..4780dac0 100644 --- a/R/tmapLeafletComp.R +++ b/R/tmapLeafletComp.R @@ -84,7 +84,7 @@ tmapLeafletCompWidth.tm_compass = function(comp, o) { #' @method tmapLeafletLegPlot tm_compass #' @export tmapLeafletLegPlot.tm_compass = function(comp, lf, o) { - lf |> leafem::addLogo(system.file(paste0("img/compass_", comp$type, ".png"), package = "tmap"), src = "local", position = leaflet_pos(comp$position), width = 120, height = 120) + lf %>% leafem::addLogo(system.file(paste0("img/compass_", comp$type, ".png"), package = "tmap"), src = "local", position = leaflet_pos(comp$position), width = 120, height = 120) } @@ -113,7 +113,7 @@ tmapLeafletCompWidth.tm_scalebar = function(comp, o) { #' @method tmapLeafletLegPlot tm_scalebar #' @export tmapLeafletLegPlot.tm_scalebar = function(comp, lf, o) { - lf |> leaflet::addScaleBar(position = leaflet_pos(comp$position)) + lf %>% leaflet::addScaleBar(position = leaflet_pos(comp$position)) } @@ -142,7 +142,7 @@ tmapLeafletCompWidth.tm_credits = function(comp, o) { #' @method tmapLeafletLegPlot tm_credits #' @export tmapLeafletLegPlot.tm_credits = function(comp, lf, o) { - #lf |> leafem::addLogo(system.file(paste0("img/credits_", comp$type, ".png"), package = "tmap"), src = "local", position = paste(unlist(comp$position[c("pos.v", "pos.h")]), collapse = ""), width = 120, height = 120) + #lf %>% leafem::addLogo(system.file(paste0("img/credits_", comp$type, ".png"), package = "tmap"), src = "local", position = paste(unlist(comp$position[c("pos.v", "pos.h")]), collapse = ""), width = 120, height = 120) message("tm_credits not implemented yet for view mode") lf } @@ -172,7 +172,7 @@ tmapLeafletCompWidth.tm_mouse_coordinates = function(comp, o) { #' @method tmapLeafletLegPlot tm_mouse_coordinates #' @export tmapLeafletLegPlot.tm_mouse_coordinates = function(comp, lf, o) { - lf |> leafem::addMouseCoordinates() + lf %>% leafem::addMouseCoordinates() } diff --git a/R/tmapLeafletLegend.R b/R/tmapLeafletLegend.R index 8a1c7298..e0fad050 100644 --- a/R/tmapLeafletLegend.R +++ b/R/tmapLeafletLegend.R @@ -135,7 +135,7 @@ tmapLeaflet_legend = function(cmp, lf, o, orientation) { cmp$tr$rev(x2) } - lf |> leaflegend::addLegendNumeric(position=legpos, + lf %>% leaflegend::addLegendNumeric(position=legpos, orientation = orientation, group = group, height = {if (orientation == "horizontal") 20 else 200}, @@ -201,7 +201,7 @@ tmapLeaflet_legend = function(cmp, lf, o, orientation) { - lf |> leaflegend::addLegendImage(symbols$iconUrl, + lf %>% leaflegend::addLegendImage(symbols$iconUrl, labels = lab, width = symbols$iconWidth, height = symbols$iconHeight, @@ -215,7 +215,7 @@ tmapLeaflet_legend = function(cmp, lf, o, orientation) { className = leg_className) } backg <- htmltools::tags$style(paste0("#", layerId, " { background: ", substr(cmp$bg.color,1,7), "; opacity: ", cmp$bg.alpha, "}")) - lf2 |> htmlwidgets::prependContent(backg) + lf2 %>% htmlwidgets::prependContent(backg) } diff --git a/R/tmapLeafletShape.R b/R/tmapLeafletShape.R index d93c3d15..585de81c 100644 --- a/R/tmapLeafletShape.R +++ b/R/tmapLeafletShape.R @@ -1,8 +1,8 @@ tmapLeafletShape = function(bbx, facet_row, facet_col, facet_page, o) { bbx = unname(bbx) - get_lf(facet_row, facet_col, facet_page) |> - leaflet::fitBounds(bbx[1], bbx[2], bbx[3], bbx[4]) |> - view_set_bounds(bbx, o) |> + get_lf(facet_row, facet_col, facet_page) %>% + leaflet::fitBounds(bbx[1], bbx[2], bbx[3], bbx[4]) %>% + view_set_bounds(bbx, o) %>% assign_lf(facet_row, facet_col, facet_page) NULL } diff --git a/R/tmapLeaflet_layers.R b/R/tmapLeaflet_layers.R index fd2386a8..ac0fbf76 100644 --- a/R/tmapLeaflet_layers.R +++ b/R/tmapLeaflet_layers.R @@ -27,12 +27,12 @@ tmapLeafletPolygons = function(shpTM, dt, pdt, popup.format, hdt, idt, gp, bbx, shp3 = suppressWarnings(sf::st_cast(shp2, "POLYGON")) gp3 = lapply(gp, function(gpi) {if (length(gpi) == 1) gpi else gpi[shp3$id]}) popups2 = popups[shp3$id] - lf |> - leafgl::addGlPolygons(data = shp3, color = gp3$col, opacity = gp3$col_alpha, fillColor = gp3$fill, fillOpacity = gp3$fill_alpha, weight = gp3$lwd, group = group, pane = pane, popup = popups2) |> + lf %>% + leafgl::addGlPolygons(data = shp3, color = gp3$col, opacity = gp3$col_alpha, fillColor = gp3$fill, fillOpacity = gp3$fill_alpha, weight = gp3$lwd, group = group, pane = pane, popup = popups2) %>% assign_lf(facet_row, facet_col, facet_page) } else { - lf |> - leaflet::addPolygons(data = shp, layerId = idt, label = hdt, color = gp$col, opacity = gp$col_alpha, fillColor = gp$fill, fillOpacity = gp$fill_alpha, weight = gp$lwd, options = opt, group = group, dashArray = lty2dash(gp$lty), popup = popups) |> + lf %>% + leaflet::addPolygons(data = shp, layerId = idt, label = hdt, color = gp$col, opacity = gp$col_alpha, fillColor = gp$fill, fillOpacity = gp$fill_alpha, weight = gp$lwd, options = opt, group = group, dashArray = lty2dash(gp$lty), popup = popups) %>% assign_lf(facet_row, facet_col, facet_page) } NULL @@ -83,12 +83,12 @@ tmapLeafletLines = function(shpTM, dt, pdt, popup.format, hdt, idt, gp, bbx, fac shp2 = sf::st_sf(id = 1:length(shp), geom = shp) shp3 = suppressWarnings(sf::st_cast(shp2, "LINESTRING")) gp3 = lapply(gp, function(gpi) {if (length(gpi) == 1) gpi else gpi[shp3$id]}) - lf |> - leafgl::addGlPolylines(data = shp3, color = gp3$col, opacity = gp3$col_alpha, weight = gp3$lwd, pane = pane, group = group) |> + lf %>% + leafgl::addGlPolylines(data = shp3, color = gp3$col, opacity = gp3$col_alpha, weight = gp3$lwd, pane = pane, group = group) %>% assign_lf(facet_row, facet_col, facet_page) } else { - lf |> - leaflet::addPolylines(data = shp, layerId = idt, label = hdt, color = gp$col, opacity = gp$col_alpha, weight = gp$lwd, group = group, options = opt, dashArray = lty2dash(gp$lty), popup = popups) |> + lf %>% + leaflet::addPolylines(data = shp, layerId = idt, label = hdt, color = gp$col, opacity = gp$col_alpha, weight = gp$lwd, group = group, options = opt, dashArray = lty2dash(gp$lty), popup = popups) %>% assign_lf(facet_row, facet_col, facet_page) } @@ -129,7 +129,7 @@ tmapLeafletSymbols = function(shpTM, dt, pdt, popup.format, hdt, idt, gp, bbx, f if (o$use.WebGL) { vary = vapply(dt, function(x)any(x!=x[1]), FUN.VALUE = logical(1))[c("col", "shape", "lwd", "lty", "fill_alpha", "col_alpha")] if (any(vary)) warning("WegGL enabled: the only supported visual variables are: fill and size. The visual variable(s) ", paste(names(vary)[vary], collapse = ", "), " are not supported. Disable WebGL to show them.", call. = FALSE) - lf |> leafgl::addGlPoints(sf::st_sf(shp), fillColor = gp2$fillColor, radius = gp2$width, fillOpacity = gp2$fillOpacity[1], pane = pane, group = group) |> + lf %>% leafgl::addGlPoints(sf::st_sf(shp), fillColor = gp2$fillColor, radius = gp2$width, fillOpacity = gp2$fillOpacity[1], pane = pane, group = group) %>% assign_lf(facet_row, facet_col, facet_page) } else { @@ -160,20 +160,20 @@ tmapLeafletSymbols = function(shpTM, dt, pdt, popup.format, hdt, idt, gp, bbx, f } } - lf |> leaflet::addMarkers(lng = coords[, 1], lat = coords[, 2], - icon = symbols, group = group, layerId = idt, label = hdt, popup = popups) |> + lf %>% leaflet::addMarkers(lng = coords[, 1], lat = coords[, 2], + icon = symbols, group = group, layerId = idt, label = hdt, popup = popups) %>% assign_lf(facet_row, facet_col, facet_page) } # if (o$use.WebGL) { - # lf |> - # leafgl::addGlPoints(sf::st_sf(shp), fillColor = gp$fill, radius = gp$size*10, fillOpacity = gp$fill_alpha, color = gp$col, opacity = gp$color_alpha, weight = gp$lwd, pane = pane, group = group) |> + # lf %>% + # leafgl::addGlPoints(sf::st_sf(shp), fillColor = gp$fill, radius = gp$size*10, fillOpacity = gp$fill_alpha, color = gp$col, opacity = gp$color_alpha, weight = gp$lwd, pane = pane, group = group) %>% # assign_lf(facet_row, facet_col, facet_page) # } else { - # lf |> - # leaflet::addCircleMarkers(lng = coords[, 1], lat = coords[, 2], fillColor = gp$fill, radius = gp$size*4, fillOpacity = gp$fill_alpha, color = gp$col, opacity = gp$color_alpha, weight = gp$lwd, group = group, options = opt) |> + # lf %>% + # leaflet::addCircleMarkers(lng = coords[, 1], lat = coords[, 2], fillColor = gp$fill, radius = gp$size*4, fillOpacity = gp$fill_alpha, color = gp$col, opacity = gp$color_alpha, weight = gp$lwd, group = group, options = opt) %>% # assign_lf(facet_row, facet_col, facet_page) # } @@ -247,8 +247,8 @@ tmapLeafletRaster = function(shpTM, dt, gp, pdt, popup.format, hdt, idt, bbx, fa lf = get_lf(facet_row, facet_col, facet_page) - lf |> - leafem::addStarsImage(shp2, band = 1, colors = pal_col, opacity = pal_opacity, group = group) |> + lf %>% + leafem::addStarsImage(shp2, band = 1, colors = pal_col, opacity = pal_opacity, group = group) %>% assign_lf(facet_row, facet_col, facet_page) } else { #shp2 = st_as_stars(list(values = tmapID), dimensions = shp) @@ -330,7 +330,7 @@ tmapLeafletText = function(shpTM, dt, gp, bbx, facet_row, facet_col, facet_page, if (!vary) { - lf = lf |> addLabelOnlyMarkers(lng = coords[, 1], lat = coords[,2], + lf = lf %>% addLabelOnlyMarkers(lng = coords[, 1], lat = coords[,2], label=text, group=group, #layerId = ids, @@ -344,7 +344,7 @@ tmapLeafletText = function(shpTM, dt, gp, bbx, facet_row, facet_col, facet_page, options = markerOptions(pane = pane)) } else { for (i in 1:length(text)) { - lf = lf |> addLabelOnlyMarkers(lng = coords[i,1], lat = coords[i,2], + lf = lf %>% addLabelOnlyMarkers(lng = coords[i,1], lat = coords[i,2], label=text[i], group=group, #layerId = ids[i], diff --git a/R/tmapShape.R b/R/tmapShape.R index 32533da9..d48026d2 100644 --- a/R/tmapShape.R +++ b/R/tmapShape.R @@ -133,7 +133,7 @@ tmapShape.SpatRaster = function(shp, is.main, crs, bbox, unit, filter, shp_name, names(ctabs) = dtcols names(cats) = dtcols - + # tmf not defined? make_by_vars(dt, tmf, smeta) if (is.null(filter)) filter = rep(TRUE, nrow(dt))