Skip to content

Commit

Permalink
Merge pull request #89 from trafficonese/master
Browse files Browse the repository at this point in the history
fix checkDim / checkDimPop, remove warnings for diff lengths, fix dependency order
  • Loading branch information
trafficonese authored Jun 2, 2024
2 parents 5bc0eff + 32bab75 commit 141523d
Show file tree
Hide file tree
Showing 15 changed files with 517 additions and 86 deletions.
4 changes: 3 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
^experiments
^\.travis\.yml$
^CODE_OF_CONDUCT\.md$
^README\.Rmd$
^README\.Rmd$
^\.github$
^codecov\.yml$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
50 changes: 50 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: '3.6'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
48 changes: 48 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
50 changes: 50 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Test coverage
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
28 changes: 16 additions & 12 deletions R/utils-color.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@
#' makeColorMatrix(data.frame(matrix(1:99, ncol = 3, byrow = TRUE)), data.frame(x=c(1:33)))
#'
#' ## For characters
#' library(leaflet)
#' makeColorMatrix("red", breweries91)
#' makeColorMatrix("blue", breweries91)
#' makeColorMatrix("#36ba01", breweries91)
#' makeColorMatrix("founded", data.frame(breweries91))
#' testdf <- data.frame(
#' texts = LETTERS[1:10],
#' vals = 1:10,
#' vals1 = 11:20
#' )
#' makeColorMatrix("red", testdf)
#' makeColorMatrix("val", testdf)
#'
#' ## For formulaes
#' makeColorMatrix(~founded, breweries91)
#' makeColorMatrix(~founded + zipcode, breweries91)
#' makeColorMatrix(~vals, testdf)
#' makeColorMatrix(~vals1, testdf)
#'
#' ## For JSON
#' library(jsonify)
Expand Down Expand Up @@ -160,8 +162,9 @@ makeColorMatrix.POSIXlt <- makeColorMatrix.Date
#' @param x The color vector
#' @param data The dataset
checkDim <- function(x, data) {
if (is.null(data)) { return(x) }
if (inherits(data, "sfc")) nro_d = length(data) else nro_d = nrow(data)
if (length(grep("MULTI", sf::st_geometry_type(data))) > 0) {
if (inherits(data, c("sf","sfc")) && length(grep("MULTI", sf::st_geometry_type(data))) > 0) {
lnths = lengths(sf::st_geometry(data))
} else {
lnths = nro_d
Expand All @@ -172,11 +175,12 @@ checkDim <- function(x, data) {
" Just the first color is used.")
x <- x[1,,drop = FALSE]
}
} else {
}
else {
len_x <- length(x)
if ((length(x) != 1) && (len_x != nro_d)) {
warning("Length of color vector does not match number of data rows.\n",
" The vector is repeated to match the number of rows.")
if ((len_x != nro_d)) {
# warning("Length of color vector does not match number of data rows.\n",
# " The vector is repeated to match the number of rows.")
x <- rep(x, ceiling(nro_d / len_x))[1:nro_d]
}
if (any(lnths != 1) & length(lnths) == nro_d & length(x) != 1) {
Expand Down
13 changes: 7 additions & 6 deletions R/utils-popup.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ makePopup.character <- function(x, data) {
makePopup.shiny.tag <- function(x, data) {
x <- as.character(x)
x <- checkDimPop(x, data)
# if (length(x) == 1) {
if (length(x) == 1) {
htmltools::HTML(x)
# } else {
# lapply(x, htmltools::HTML)
# }
} else {
lapply(x, htmltools::HTML)
}
}

#' @export
Expand Down Expand Up @@ -102,11 +102,12 @@ makePopup.default <- function(x, data) {
#' @param x The popup vector
#' @param data The dataset
checkDimPop <- function(x, data) {
if (is.null(data)) { return(x) }
if (inherits(data, "sfc")) nro_d = length(data) else nro_d = nrow(data)
len_x <- length(x)
if (len_x != nro_d) {
warning("Length of popups does not match number of data rows.\n",
" The vector is repeated to match the number of rows.")
# warning("Length of popups does not match number of data rows.\n",
# " The vector is repeated to match the number of rows.")
x <- rep(x, ceiling(nro_d / len_x))[1:nro_d]
}
return(x)
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@

# leafgl - performant WebGL rendering for leaflet

[![Travis build
status](https://travis-ci.org/r-spatial/leafgl.svg?branch=master)](https://travis-ci.org/r-spatial/leafgl)
<!-- badges: start -->
[![R-CMD-check](https://github.com/r-spatial/leafgl/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-spatial/leafgl/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/r-spatial/leafgl/branch/master/graph/badge.svg)](https://app.codecov.io/gh/r-spatial/leafgl?branch=master)

[![monthly](http://cranlogs.r-pkg.org/badges/leafgl)](https://www.rpackages.io/package/leafgl)
[![total](http://cranlogs.r-pkg.org/badges/grand-total/leafgl)](https://www.rpackages.io/package/leafgl)
[![CRAN](http://www.r-pkg.org/badges/version/leafgl?color=009999)](https://cran.r-project.org/package=leafgl)
[![status](https://tinyverse.netlify.com/badge/leafgl)](https://CRAN.R-project.org/package=leafgl)
<!-- badges: end -->

An R package for fast web gl rendering of features on leaflet maps. It’s
an R port of <https://github.com/robertleeplummerjr/Leaflet.glify> where
Expand Down
14 changes: 14 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
comment: false

coverage:
status:
project:
default:
target: auto
threshold: 1%
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true
16 changes: 9 additions & 7 deletions man/makeColorMatrix.Rd

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

18 changes: 14 additions & 4 deletions tests/testthat/test-leafgl-addGlPoints.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@ test_that("addGlPoints works", {
y = rnorm(n, 49, 0.8))
pts = st_as_sf(df1, coords = c("x", "y"), crs = 4326)


m = leaflet() %>%
addGlPoints(data = pts, group = "pts", digits = 5)
addGlPoints(data = pts, group = "pts", digits = 5,
randomarg=TRUE,
by ="row", numeric_dates=F)
expect_is(m, "leaflet")


m = leaflet() %>%
addGlPoints(data = pts, group = "pts", digits = 5)
expect_is(m, "leaflet")

m = leaflet() %>%
addGlPoints(data = pts, layerId = "someid", src = TRUE)
expect_is(m, "leaflet")
expect_identical(m$dependencies[[length(m$dependencies)]]$name, paste0("someid","dat"))
expect_identical(m$dependencies[[length(m$dependencies)-1]]$name, paste0("someid","dat"))
expect_identical(m$dependencies[[length(m$dependencies)]]$name, paste0("someid","col"))

m = leaflet() %>%
addGlPoints(data = pts, group = NULL)
Expand All @@ -28,12 +36,14 @@ test_that("addGlPoints works", {
m = leaflet() %>%
addGlPoints(data = pts, layerId = NULL, group = NULL, src = TRUE)
expect_is(m, "leaflet")
expect_identical(m$dependencies[[length(m$dependencies)]]$name, "data-ptsdat")
expect_identical(m$dependencies[[length(m$dependencies)-1]]$name, "data-ptsdat")
expect_identical(m$dependencies[[length(m$dependencies)]]$name, "data-ptscol")

m = leaflet() %>%
addGlPoints(data = breweries91, src = TRUE)
expect_is(m, "leaflet")
expect_identical(m$dependencies[[length(m$dependencies)]]$name, "glpoints-ptsdat")
expect_identical(m$dependencies[[length(m$dependencies)-1]]$name, "glpoints-ptsdat")
expect_identical(m$dependencies[[length(m$dependencies)]]$name, "glpoints-ptscol")

m = leaflet() %>%
addGlPoints(data = breweries91, src = TRUE, radius = 5)
Expand Down
30 changes: 29 additions & 1 deletion tests/testthat/test-leafgl-addGlPolygons.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,38 @@ test_that("addGlPolygons works", {
library(sf)

gadm = st_as_sf(gadmCHE)
single_poly <- suppressWarnings(st_cast(gadm, "POLYGON"))

m = leaflet() %>%
addGlPolygons(data = suppressWarnings(st_cast(gadm, "POLYGON")),
addGlPolygons(data = single_poly,
group = "pls", digits = 5)
expect_is(m, "leaflet")

# Group = NULL #######
m = leaflet() %>%
addGlPolygons(data = single_poly, group = NULL, digits = 5)
expect_is(m, "leaflet")

m = leaflet() %>%
addGlPolygons(data = single_poly, group = NULL, src = TRUE, digits = 5)
expect_is(m, "leaflet")

## Spatial Data #########
spatialdf <- as(single_poly, "Spatial")
m = leaflet() %>%
addGlPolygons(data = spatialdf, digits = 5)
expect_is(m, "leaflet")

m = leaflet() %>%
addGlPolygons(data = spatialdf, src = TRUE, digits = 5)
expect_is(m, "leaflet")

## Multi #########
expect_error(
leaflet() %>%
addGlPolygons(data = gadm, digits = 5))
expect_error(
leaflet() %>%
addGlPolygons(data = gadm, src = TRUE, digits = 5))

})
Loading

0 comments on commit 141523d

Please sign in to comment.