From dd425588d88ef361cd738083639a52fe148ab28b Mon Sep 17 00:00:00 2001 From: Martin Jung <3788377+Martin-Jung@users.noreply.github.com> Date: Thu, 5 Dec 2024 12:57:32 +0100 Subject: [PATCH] Small updates and convenience stuff (#8) * Documentation and pkgdown addition * Adding datapaths as entry * :rocket: negated in function --- .github/workflows/pkgdown.yaml | 49 +++++++++++++++++++++++++++++++ DESCRIPTION | 3 +- NAMESPACE | 3 +- R/data.R | 24 +++++++++++++++ R/misc_notIn.R | 19 ++++++++++++ R/spl_replaceGriddedNA.R | 4 +-- README.md | 34 +++++++++++++++++++++ _pkgdown.yml | 4 +++ data/bnr_datapaths.rda | Bin 0 -> 265 bytes man/bnr_datapaths.Rd | 35 ++++++++++++++++++++++ man/grapes-notin-grapes.Rd | 27 +++++++++++++++++ man/sp_replaceGriddedNA.Rd | 8 +++-- tests/testthat/test-misc_tests.R | 8 ++++- 13 files changed, 210 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/pkgdown.yaml create mode 100644 R/data.R create mode 100644 R/misc_notIn.R create mode 100644 _pkgdown.yml create mode 100644 data/bnr_datapaths.rda create mode 100644 man/bnr_datapaths.Rd create mode 100644 man/grapes-notin-grapes.Rd diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..bfc9f4d --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,49 @@ +# 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: + release: + types: [published] + workflow_dispatch: + +name: pkgdown.yaml + +permissions: read-all + +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@v4 + + - 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/github-pages-deploy-action@v4.5.0 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/DESCRIPTION b/DESCRIPTION index e17eef6..d860387 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,7 +13,7 @@ Authors@R: ) Description: What the package does (one paragraph). License: MIT + file LICENSE -URL: https://github.com/iiasa/BNRTools +URL: https://github.com/iiasa/BNRTools, https://iiasa.github.io/BNRTools/ BugReports: https://github.com/iiasa/BNRTools/issues Depends: R (>= 3.6) Imports: @@ -27,3 +27,4 @@ Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 Config/testthat/edition: 3 +LazyData: true diff --git a/NAMESPACE b/NAMESPACE index a74b708..e8b90d0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export("%notin%") export(misc_sanitizeNames) +export(sp_replaceGriddedNA) export(sp_resampleRas) -export(sp_replaceGriddedNA) \ No newline at end of file diff --git a/R/data.R b/R/data.R new file mode 100644 index 0000000..a96fa12 --- /dev/null +++ b/R/data.R @@ -0,0 +1,24 @@ +#' Table with default paths to commonly used spatial input files +#' +#' @description +#' This dataset contains path names to commonly-used spatial data files. Given that +#' those files are usually quite large, we here only describe where to find them internally +#' and not upload the data itself. +#' Medium-long-term this could be improved by relying on github LFS systems or our own gitlab +#' instance. +#' +#' @details +#' The file has the following columns: +#' +#' [*] 'drive': The path to drive where the data is stored (Default: \code{'P:/bnr/'}). Can be system dependent (Windows/Linux). +#' [*] 'access': A non-structured field containing the list of people that have access (for example \code{'IBF'} or \code{'bnr'}). +#' [*] 'group': A field entry describing to what this file belongs to (i.e. \code{"EPIC"}). +#' [*] 'filename': The actual filename +#' +#' @note +#' To update or overwrite, load the file and update, then apply +#' \code{usethis::use_data(bnr_datapaths, overwrite = TRUE) }. +#' +#' @format A [data.frame] containing paths to key spatial data sources. +#' @source Manually updated and curated by BNR researchers +"bnr_datapaths" diff --git a/R/misc_notIn.R b/R/misc_notIn.R new file mode 100644 index 0000000..8b6bf6e --- /dev/null +++ b/R/misc_notIn.R @@ -0,0 +1,19 @@ +#' Inverse of 'in' call +#' +#' @description +#' Calculates the set of entries not present in the second vector. +#' Added for convenience since this is not supported by default in R. +#' +#' @param a First [`vector`] object. +#' @param b Second [`vector`] object. +#' +#' @returns A [`vector`] of [`logical`] entries of \code{'a'} not present in \code{'b'}. +#' @examples +#' # example code +# lu <- c("Forest", "Cropland", "Wetland", "OtherLand") +# lu2 <- c("Forest", "Wetland", "otherland") +# which(lu %notin% lu2) +#' @keywords utils +#' @author Martin Jung +#' @export +`%notin%` = function(a, b){!(a %in% b)} diff --git a/R/spl_replaceGriddedNA.R b/R/spl_replaceGriddedNA.R index d4302fb..1e06d5c 100644 --- a/R/spl_replaceGriddedNA.R +++ b/R/spl_replaceGriddedNA.R @@ -17,10 +17,10 @@ #' #' @examples #' # Example -#' s <- rast(system.file("ex/logo.tif", package="terra")) +#' s <- terra::rast(system.file("ex/logo.tif", package="terra")) #' s[sample(1:terra::ncell(s), 100)] <- NA #' sfill <- sp_replaceGriddedNA(s, value = 100) -#' plot(sfill) +#' terra::plot(sfill) #' #' @returns A object of the same type as the input but with no-data values replaced with \code{'value'}. #' @author Martin Jung diff --git a/README.md b/README.md index 5563b18..cf52678 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,37 @@ See this [website](https://r-pkgs.org/) for more general help and examples in de ## Code of Conduct Please note that the BNRTools project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/1/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. + +## Contributors + + + + + + + +All contributions to this project are gratefully acknowledged using the [`allcontributors` package](https://github.com/ropensci/allcontributors) following the [all-contributors](https://allcontributors.org) specification. Contributions of any kind are welcome! + +
+
+
+ +Martin-Jung + |
+
+
+
+ +mhesselbarth + |
+