From aeeecce271de10dcaeeeac0ec298c2222724222a Mon Sep 17 00:00:00 2001 From: Bas Latcham Date: Tue, 8 Nov 2022 08:04:35 +1100 Subject: [PATCH 1/5] refactor: :recycle: Use {sf} to create the bbox --- R/functions.R | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/R/functions.R b/R/functions.R index 7cf291b..8596690 100644 --- a/R/functions.R +++ b/R/functions.R @@ -6,10 +6,8 @@ #' code_bbox <- function(mbb) { bb_code <- glue::glue( - 'bbox <- c("left" = {mbb[1,1]}, "bottom" = {mbb[2,1]}, "right" = {mbb[1,2]}, "top" = {mbb[2,2]}) - attr(bbox, "class") <- "bbox" - attr(bbox, "crs") <- sf::st_crs(4326)' - ) + 'bbox <- sf::st_bbox(c("xmin" = {mbb[["xmin"]]}, "ymin" = {mbb[["ymin"]]}, "xmax" = {mbb[["xmax"]]}, "ymax" = {mbb[["ymax"]]}), crs = 4326L)' + ) rstudioapi::insertText(text = bb_code) invisible() } @@ -23,12 +21,18 @@ code_bbox <- function(mbb) { #' @return a matrix manual_bbox <- function(coords) { # the + 360 is probably not always valid - left <- coords[[1]][[1]] - right <- coords[[3]][[1]] - bottom <- coords[[1]][[2]] - top <- coords[[3]][[2]] - bb <- rbind(c(left, right), c(bottom, top)) - dimnames(bb) <- list(c("x", "y"), c("min", "max")) - attr(bb, "class") <- "bbox" - return(bb) + xmin <- coords[[1L]][[1L]] + xmax <- coords[[3L]][[1L]] + ymin <- coords[[1L]][[2L]] + ymax <- coords[[3L]][[2L]] + + sf::st_bbox( + c( + "xmin" = xmin, + "ymin" = ymin, + "xmax" = xmax, + "ymax" = ymax + ), + crs = 4326L + ) } From 498007699079a93ec20fe879b6db38997a981887 Mon Sep 17 00:00:00 2001 From: Bas Latcham Date: Tue, 8 Nov 2022 08:05:23 +1100 Subject: [PATCH 2/5] build: :heavy_plus_sign: Add {sf}, remove various tidyverse packs --- DESCRIPTION | 13 ++++++------- R/bbb-package.R | 1 - R/utils-tidy-eval.R | 47 --------------------------------------------- man/bbb-package.Rd | 3 +-- man/morph.Rd | 1 - 5 files changed, 7 insertions(+), 58 deletions(-) delete mode 100644 R/utils-tidy-eval.R diff --git a/DESCRIPTION b/DESCRIPTION index fd543c0..3e38f34 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,18 +9,17 @@ Description: Interactively create a bounding box. Drag a rectangle, make a License: MIT + file LICENSE URL: https://github.com/baslat/bbb BugReports: https://github.com/baslat/bbb/issues -Imports: +Imports: glue, leaflet, leaflet.extras, magrittr, - purrr, - rlang (>= 0.1.2), rstudioapi, - shiny, - tibble -Suggests: + sf, + shiny +Suggests: dplyr, + purrr, roxygen2, spelling, testthat (>= 3.0.0) @@ -28,4 +27,4 @@ Config/testthat/edition: 3 Encoding: UTF-8 Language: en-US LazyData: true -RoxygenNote: 7.1.1 +RoxygenNote: 7.2.1 diff --git a/R/bbb-package.R b/R/bbb-package.R index c1955b4..b30bbda 100644 --- a/R/bbb-package.R +++ b/R/bbb-package.R @@ -4,6 +4,5 @@ # The following block is used by usethis to automatically manage # roxygen namespace tags. Modify with care! ## usethis namespace: start -#' @importFrom tibble tibble ## usethis namespace: end NULL diff --git a/R/utils-tidy-eval.R b/R/utils-tidy-eval.R deleted file mode 100644 index b4e6c7f..0000000 --- a/R/utils-tidy-eval.R +++ /dev/null @@ -1,47 +0,0 @@ -#' Tidy eval helpers -#' -#' @description -#' -#' * \code{\link[rlang]{sym}()} creates a symbol from a string and -#' \code{\link[rlang:sym]{syms}()} creates a list of symbols from a -#' character vector. -#' -#' * \code{\link[rlang:nse-defuse]{enquo}()} and -#' \code{\link[rlang:nse-defuse]{enquos}()} delay the execution of one or -#' several function arguments. \code{enquo()} returns a single quoted -#' expression, which is like a blueprint for the delayed computation. -#' \code{enquos()} returns a list of such quoted expressions. -#' -#' * \code{\link[rlang:nse-defuse]{expr}()} quotes a new expression _locally_. It -#' is mostly useful to build new expressions around arguments -#' captured with [enquo()] or [enquos()]: -#' \code{expr(mean(!!enquo(arg), na.rm = TRUE))}. -#' -#' * \code{\link[rlang]{as_name}()} transforms a quoted variable name -#' into a string. Supplying something else than a quoted variable -#' name is an error. -#' -#' That's unlike \code{\link[rlang]{as_label}()} which also returns -#' a single string but supports any kind of R object as input, -#' including quoted function calls and vectors. Its purpose is to -#' summarise that object into a single label. That label is often -#' suitable as a default name. -#' -#' If you don't know what a quoted expression contains (for instance -#' expressions captured with \code{enquo()} could be a variable -#' name, a call to a function, or an unquoted constant), then use -#' \code{as_label()}. If you know you have quoted a simple variable -#' name, or would like to enforce this, use \code{as_name()}. -#' -#' To learn more about tidy eval and how to use these tools, visit -#' \url{https://tidyeval.tidyverse.org} and the -#' \href{https://adv-r.hadley.nz/metaprogramming.html}{Metaprogramming -#' section} of \href{https://adv-r.hadley.nz}{Advanced R}. -#' -#' @md -#' @name tidyeval -#' @keywords internal -#' @importFrom rlang expr enquo enquos sym syms .data := as_name as_label -#' @aliases expr enquo enquos sym syms .data := as_name as_label -#' @export expr enquo enquos sym syms .data := as_name as_label -NULL diff --git a/man/bbb-package.Rd b/man/bbb-package.Rd index 29c8824..e31c112 100644 --- a/man/bbb-package.Rd +++ b/man/bbb-package.Rd @@ -6,8 +6,7 @@ \alias{bbb-package} \title{bbb: Build Bounding Boxes} \description{ -Interactively create a bounding box. Drag a - rectangle, make a bounding box. +Interactively create a bounding box. Drag a rectangle, make a bounding box. } \seealso{ Useful links: diff --git a/man/morph.Rd b/man/morph.Rd index f0f2f6c..df691b4 100644 --- a/man/morph.Rd +++ b/man/morph.Rd @@ -27,5 +27,4 @@ attr(bbox, "class") <- "bbox" bbox2 <- morph(bbox, "xy_string") } - } From 174fdbc3f7b3fffeb1c56d2476e687dbb17173b3 Mon Sep 17 00:00:00 2001 From: Bas Latcham Date: Tue, 8 Nov 2022 08:05:41 +1100 Subject: [PATCH 3/5] Increment version number to 1.0.0 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3e38f34..f16d6de 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: bbb Title: Build Bounding Boxes -Version: 0.4.1 +Version: 1.0.0 Author: Abasi Latcham Maintainer: Bas Description: Interactively create a bounding box. Drag a rectangle, make a diff --git a/NEWS.md b/NEWS.md index 1917c87..d263447 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +# bbb 1.0.0 + # bbb 0.4.1 * `box` now returns the code to set CRS attribute with EPSG:4326 in accordance with [Stack From 79c9449fb5c108075501a077c8e0e2df60a4a58d Mon Sep 17 00:00:00 2001 From: Bas Latcham Date: Tue, 8 Nov 2022 08:07:18 +1100 Subject: [PATCH 4/5] docs: :memo: News --- NEWS.md | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/NEWS.md b/NEWS.md index d263447..d910942 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,33 +1,41 @@ # bbb 1.0.0 +- Use `{sf}` to make the bounding box with `sf::st_bbox()`. + # bbb 0.4.1 -* `box` now returns the code to set CRS attribute with EPSG:4326 in accordance + +- `box` now returns the code to set CRS attribute with EPSG:4326 in accordance with [Stack Exchange](https://gis.stackexchange.com/questions/310091/what-does-the-default-crs-being-epsg3857-in-leaflet-mean) # bbb 0.4.0 -* `box` now returns the code to set CRS attribute with EPSG:3857 in accordance + +- `box` now returns the code to set CRS attribute with EPSG:3857 in accordance with [leaflet documentation](https://rstudio.github.io/leaflet/projections.html) , and this is respected by `morph` -* minor didactic tweaks +- minor didactic tweaks # bbb 0.3.0 -* adds `morph` functions to change the format of bounding boxes -* fixes an incorrect reference in the returned code -* changes to use left, right etc instead of xmin, xmax in returned code -* removes `crayon` from dependencies -* adds `dplyr` to `suggests` + +- adds `morph` functions to change the format of bounding boxes +- fixes an incorrect reference in the returned code +- changes to use left, right etc instead of xmin, xmax in returned code +- removes `crayon` from dependencies +- adds `dplyr` to `suggests` # bbb 0.2.0 -* removes pipe from returned code -* unforces bbox code to print to console -* makes the instructions more explicit -* removes `sf` from dependencies -* removes most of the unnecessary features + +- removes pipe from returned code +- unforces bbox code to print to console +- makes the instructions more explicit +- removes `sf` from dependencies +- removes most of the unnecessary features # bbb 0.1.1 -* forces bbox code to print to console -* comments out creation of global objects + +- forces bbox code to print to console +- comments out creation of global objects # bbb 0.1.0 -* Added a `NEWS.md` file to track changes to the package. + +- Added a `NEWS.md` file to track changes to the package. From 081e633799b7fe2b6bb1973f65175ba4c02cd110 Mon Sep 17 00:00:00 2001 From: Bas Latcham Date: Tue, 8 Nov 2022 08:08:31 +1100 Subject: [PATCH 5/5] ci: :construction_worker: Add GHA --- .Rbuildignore | 1 + .github/.gitignore | 1 + .github/workflows/R-CMD-check.yaml | 29 +++++++++++++++++++++++++++++ README.md | 4 ++-- 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 .github/.gitignore create mode 100644 .github/workflows/R-CMD-check.yaml diff --git a/.Rbuildignore b/.Rbuildignore index e13c405..31e3754 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,4 @@ ^.*\.Rproj$ ^\.Rproj\.user$ ^LICENSE\.md$ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..f4b17a4 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,29 @@ +# 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: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + 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::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 diff --git a/README.md b/README.md index 4f70fc0..f4724c8 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,10 @@ # bbb: build bounding boxes +[![R-CMD-check](https://github.com/baslat/bbb/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/baslat/bbb/actions/workflows/R-CMD-check.yaml) -The goal of bbb is to allow for the interactive creation of bounding boxes +The goal of bbb is to allow for the interactive creation of spatial bounding boxes inside R Studio. ## Installation @@ -25,4 +26,3 @@ inclined to manually call it, you can do so with ``` r bbb::box() ``` -