Skip to content

Commit

Permalink
Small updates and convenience stuff (#8)
Browse files Browse the repository at this point in the history
* Documentation and pkgdown addition

* Adding datapaths as entry

* 🚀 negated in function
  • Loading branch information
Martin-Jung authored Dec 5, 2024
1 parent 50672cc commit dd42558
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 8 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
clean: false
branch: gh-pages
folder: docs
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -27,3 +27,4 @@ Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Config/testthat/edition: 3
LazyData: true
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -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)
24 changes: 24 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -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"
19 changes: 19 additions & 0 deletions R/misc_notIn.R
Original file line number Diff line number Diff line change
@@ -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)}
4 changes: 2 additions & 2 deletions R/spl_replaceGriddedNA.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


<!--- Added via allcontributors::add_contributors(type = "code") --->
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->

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!

<table>

<tr>
<td align="center">
<a href="https://github.com/Martin-Jung">
<img src="https://avatars.githubusercontent.com/u/3788377?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/iiasa/BNRTools/commits?author=Martin-Jung">Martin-Jung</a>
</td>
<td align="center">
<a href="https://github.com/mhesselbarth">
<img src="https://avatars.githubusercontent.com/u/29225293?v=4" width="100px;" alt=""/>
</a><br>
<a href="https://github.com/iiasa/BNRTools/commits?author=mhesselbarth">mhesselbarth</a>
</td>
</tr>

</table>

<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

4 changes: 4 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
url: https://iiasa.github.io/BNRTools/
template:
bootstrap: 5

Binary file added data/bnr_datapaths.rda
Binary file not shown.
35 changes: 35 additions & 0 deletions man/bnr_datapaths.Rd

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

27 changes: 27 additions & 0 deletions man/grapes-notin-grapes.Rd

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

8 changes: 5 additions & 3 deletions man/sp_replaceGriddedNA.Rd

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

8 changes: 7 additions & 1 deletion tests/testthat/test-misc_tests.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
test_that("Basic unit tests for misc functions", {
test_that("Basic unit tests for small misc functions", {
expect_equal(misc_sanitizeNames("Climate-temperature2015"), "Climate_temperature2015")

# Not in function\
lu <- c("Forest", "Cropland", "Wetland", "OtherLand")
lu2 <- c("Forest", "Wetland", "otherland")
test <- which(lu %notin% lu2)
expect_equal(test, c(2,4))
})

0 comments on commit dd42558

Please sign in to comment.