From ddf5f4dd83ea3dfcb336fcc43d27641c4eeaa8f8 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Tue, 19 Jan 2021 16:53:40 +0100 Subject: [PATCH 01/15] Bump dev version number --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3ce55ae..23cba90 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: watina Title: Querying And Processing Data From The INBO Watina Database -Version: 0.4.0 +Version: 0.4.0.9000 Description: The R-package watina contains functions to query and process data from the Watina database at the Research Institute for Nature and Forest (INBO). This database primarily provides From 1c1236606d48c586bccbd06de6c0d8a6f02eaef0 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Tue, 19 Jan 2021 16:55:33 +0100 Subject: [PATCH 02/15] Don't import dplyr::row_number() --- NAMESPACE | 1 - R/get.R | 1 - 2 files changed, 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 9a40c7e..035b880 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -46,7 +46,6 @@ importFrom(dplyr,n) importFrom(dplyr,pull) importFrom(dplyr,rename) importFrom(dplyr,right_join) -importFrom(dplyr,row_number) importFrom(dplyr,rowwise) importFrom(dplyr,select) importFrom(dplyr,semi_join) diff --git a/R/get.R b/R/get.R index e18f3ca..1d07d08 100644 --- a/R/get.R +++ b/R/get.R @@ -322,7 +322,6 @@ #' distinct #' arrange #' group_by -#' row_number #' ungroup #' sql get_locs <- function(con, From 42b010d1101dfae7d5a5f70573f8654ac238ecb5 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Wed, 20 Jan 2021 11:26:04 +0100 Subject: [PATCH 03/15] Vign 110+210: drop unneeded packages --- vignettes/v110_xg3.Rmd | 2 -- vignettes/v210_chem.Rmd | 2 -- 2 files changed, 4 deletions(-) diff --git a/vignettes/v110_xg3.Rmd b/vignettes/v110_xg3.Rmd index ac144af..c385759 100644 --- a/vignettes/v110_xg3.Rmd +++ b/vignettes/v110_xg3.Rmd @@ -14,9 +14,7 @@ knitr::opts_chunk$set( eval = FALSE ) library(watina) -library(sf) library(dplyr) -library(stringr) library(knitr) ``` diff --git a/vignettes/v210_chem.Rmd b/vignettes/v210_chem.Rmd index b25c55c..05d2a6f 100644 --- a/vignettes/v210_chem.Rmd +++ b/vignettes/v210_chem.Rmd @@ -14,9 +14,7 @@ knitr::opts_chunk$set( eval = FALSE ) library(watina) -library(sf) library(dplyr) -library(stringr) library(knitr) ``` From aadb9da91ef25b1070b4ed7271a8a7beb0a259a1 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Wed, 9 Jun 2021 18:37:51 +0200 Subject: [PATCH 04/15] GHA workflows: implement (as in n2khab) --- .github/.gitignore | 1 + .github/workflows/R-CMD-check-latest.yaml | 95 +++++++++++++++++++++++ .github/workflows/R-CMD-check.yaml | 85 ++++++++++++++++++++ .github/workflows/site-deploy.yaml | 63 +++++++++++++++ .github/workflows/site-devel.yaml | 67 ++++++++++++++++ .travis.yml | 33 -------- README.md | 5 +- 7 files changed, 314 insertions(+), 35 deletions(-) create mode 100644 .github/.gitignore create mode 100644 .github/workflows/R-CMD-check-latest.yaml create mode 100644 .github/workflows/R-CMD-check.yaml create mode 100644 .github/workflows/site-deploy.yaml create mode 100644 .github/workflows/site-devel.yaml delete mode 100644 .travis.yml 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-latest.yaml b/.github/workflows/R-CMD-check-latest.yaml new file mode 100644 index 0000000..df7c164 --- /dev/null +++ b/.github/workflows/R-CMD-check-latest.yaml @@ -0,0 +1,95 @@ +# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. +# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions +on: + push: + branches: + - dev* + pull_request: + branches: + - main + - master + schedule: + - cron: '0 3 14 * *' + +name: R-CMD-check-latest + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: ubuntu-20.04, r: 'release'} + - {os: ubuntu-20.04, r: 'devel'} + - {os: ubuntu-18.04, r: 'release'} + - {os: ubuntu-18.04, r: 'devel'} + - {os: windows-latest, r: 'release'} + - {os: macOS-latest, r: 'release'} + + env: + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v1 + with: + r-version: ${{ matrix.config.r }} + + - uses: r-lib/actions/setup-pandoc@v1 + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Restore (or define new) R package cache + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ matrix.config.os }}-${{ secrets.CACHE_VERSION }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + + - name: Install system dependencies (Linux) + if: runner.os == 'Linux' + run: | + sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable + sudo apt-get update + while read -r cmd + do + eval sudo $cmd + done < <(Rscript -e 'release <- system("lsb_release -rs", intern = TRUE); writeLines(remotes::system_requirements("ubuntu", release))') + + - name: Install system dependencies (macOS) + if: runner.os == 'macOS' + run: | + brew install pkg-config + brew install udunits + brew install gdal + + - name: Install package dependencies + run: | + remotes::install_deps(dependencies = TRUE) + remotes::install_cran("rcmdcheck") + shell: Rscript {0} + + - name: Check + env: + _R_CHECK_CRAN_INCOMING_REMOTE_: false + run: | + options(rmarkdown.html_vignette.check_title = FALSE) + rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") + shell: Rscript {0} + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@main + with: + name: ${{ matrix.config.os }}-r${{ matrix.config.r }}-results + path: check diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..1ca4ad2 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,85 @@ +# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. +# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions +on: + push: + +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: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: ubuntu-18.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"} + - {os: windows-latest, r: 'release'} + - {os: macOS-latest, r: 'release'} + + env: + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true + RSPM: ${{ matrix.config.rspm }} + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v1 + with: + r-version: ${{ matrix.config.r }} + + - uses: r-lib/actions/setup-pandoc@v1 + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Restore (or define new) R package cache + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ matrix.config.os }}-${{ secrets.CACHE_VERSION }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ matrix.config.os }}-${{ secrets.CACHE_VERSION }}-${{ hashFiles('.github/R-version') }}-1- + + - name: Install system dependencies (Linux) + if: runner.os == 'Linux' + run: | + while read -r cmd + do + eval sudo $cmd + done < <(Rscript -e 'release <- system("lsb_release -rs", intern = TRUE); writeLines(remotes::system_requirements("ubuntu", release))') + + - name: Install system dependencies (macOS) + if: runner.os == 'macOS' + run: | + brew install pkg-config + brew install udunits + brew install gdal + + - name: Install package dependencies + run: | + remotes::install_deps(dependencies = TRUE) + remotes::install_cran("rcmdcheck") + shell: Rscript {0} + + - name: Check + env: + _R_CHECK_CRAN_INCOMING_REMOTE_: false + run: | + options(rmarkdown.html_vignette.check_title = FALSE) + rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") + shell: Rscript {0} + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@main + with: + name: ${{ matrix.config.os }}-r${{ matrix.config.r }}-results + path: check diff --git a/.github/workflows/site-deploy.yaml b/.github/workflows/site-deploy.yaml new file mode 100644 index 0000000..53c1212 --- /dev/null +++ b/.github/workflows/site-deploy.yaml @@ -0,0 +1,63 @@ +on: + push: + branches: + - main + - master + +name: site-deploy + +jobs: + site-deploy: + runs-on: ${{ matrix.config.os }} + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + strategy: + matrix: + config: + - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + env: + RSPM: ${{ matrix.config.rspm }} + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v1 + with: + r-version: ${{ matrix.config.r }} + + - uses: r-lib/actions/setup-pandoc@v1 + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Restore (or define new) R package cache + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ matrix.config.os }}-${{ secrets.CACHE_VERSION }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + + - name: Install system dependencies (Linux) + run: | + while read -r cmd + do + eval sudo $cmd + done < <(Rscript -e 'release <- system("lsb_release -rs", intern = TRUE); writeLines(remotes::system_requirements("ubuntu", release))') + sudo apt-get install -y libfribidi-dev libharfbuzz-dev + + - name: Install dependencies + run: | + remotes::install_deps(dependencies = TRUE) + install.packages("pkgdown") + shell: Rscript {0} + + - name: Install package + run: R CMD INSTALL . + + - name: Deploy package + run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + Rscript -e 'options(rmarkdown.html_vignette.check_title = FALSE); pkgdown::deploy_to_branch(new_process = FALSE)' diff --git a/.github/workflows/site-devel.yaml b/.github/workflows/site-devel.yaml new file mode 100644 index 0000000..8f05cd1 --- /dev/null +++ b/.github/workflows/site-devel.yaml @@ -0,0 +1,67 @@ +on: + pull_request: + branches: + - main + - master + +name: site-devel + +jobs: + site-devel: + runs-on: ${{ matrix.config.os }} + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + strategy: + matrix: + config: + - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + env: + RSPM: ${{ matrix.config.rspm }} + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v1 + with: + r-version: ${{ matrix.config.r }} + + - uses: r-lib/actions/setup-pandoc@v1 + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Restore (or define new) R package cache + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ matrix.config.os }}-${{ secrets.CACHE_VERSION }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + + - name: Install system dependencies (Linux) + run: | + while read -r cmd + do + eval sudo $cmd + done < <(Rscript -e 'release <- system("lsb_release -rs", intern = TRUE); writeLines(remotes::system_requirements("ubuntu", release))') + sudo apt-get install -y libfribidi-dev libharfbuzz-dev + + - name: Install dependencies + run: | + remotes::install_deps(dependencies = TRUE) + install.packages("pkgdown") + shell: Rscript {0} + + - name: Install package + run: R CMD INSTALL . + + - name: Build site + run: | + Rscript -e 'options(rmarkdown.html_vignette.check_title = FALSE); pkgdown::build_site()' + + - name: Upload pkgdown-site as artifact + uses: actions/upload-artifact@main + with: + name: pkgdown-site + path: docs diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8cc4803..0000000 --- a/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -addons: - apt: - sources: - - sourceline: 'ppa:ubuntugis/ubuntugis-unstable' - packages: - - libudunits2-dev - - libgdal-dev - - libproj-dev - - libgeos-dev - - libfftw3-dev - - libfribidi-dev - -language: r - -dist: bionic - -cache: packages - -r_packages: - - pkgdown - -after_success: - - R CMD INSTALL . - - Rscript -e "pkgdown::build_site(preview = FALSE)" - -deploy: - provider: pages - local_dir: docs - skip_cleanup: true - keep_history: true - github_token: $GITHUB_TOKEN - on: - branch: master diff --git a/README.md b/README.md index 327e707..108c853 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3630532.svg)](https://doi.org/10.5281/zenodo.3630532) [![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing) -[![Build Status](https://travis-ci.org/inbo/watina.svg?branch=master)](https://travis-ci.org/inbo/watina) +[![R-CMD-check](https://github.com/inbo/watina/workflows/R-CMD-check/badge.svg)](https://github.com/inbo/watina/actions?query=workflow%3AR-CMD-check) +[![site-devel](https://github.com/inbo/watina/workflows/site-devel/badge.svg)](https://github.com/inbo/watina/actions?query=workflow%3Asite-devel) ## Welcome @@ -19,7 +20,7 @@ natural areas in Flanders (Belgium) and provides: Currently the R package won't work outside INBO. -## Installing, testing and using the _watina_ package +## Installing and using the _watina_ package ### Option 1 (quick): installing without vignettes From c03e330ee8744d5d1a6fc42ad11c3b1c26ce7b07 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Wed, 9 Jun 2021 18:38:39 +0200 Subject: [PATCH 05/15] Update contrib guide (as in n2khab) - fixes #83 --- .github/CONTRIBUTING.md | 86 ++++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 13 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 3a0249f..aa9a1e9 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -25,6 +25,11 @@ Think watina is useful? Let others discover it, by telling them in person, via T Using watina for a paper you are writing? Consider [citing it][citation]. +```r +# with the watina package installed, this will return a bibliography entry: +citation("watina") +``` + ### Ask a question ⁉️ Using watina and got stuck? Browse the [documentation][website] to see if you can find a solution. Still stuck? Post your question as an [issue on GitHub][new_issue]. While we cannot offer user support, we'll try to do our best to address it, as questions often lead to better documentation or the discovery of bugs. @@ -48,6 +53,9 @@ Using watina and discovered a bug? That's annoying! Don't let others have the sa * Any details about your local setup that might be helpful in troubleshooting. * Detailed steps to reproduce the bug. +Help yourself and those you are asking for help: use the reprex package! +Usually just running [`reprex::reprex(session_info = TRUE)`](https://reprex.tidyverse.org/reference/reprex.html) on a small reproducible example will do all the magic. 🌟 + ### Improve the documentation 📖 Noticed a typo on the website? Think a function could use a better example? Good documentation makes all the difference, so your help to improve it is very welcome! @@ -58,7 +66,7 @@ Noticed a typo on the website? Think a function could use a better example? Good #### Function documentation -Functions are described as comments near their code and translated to documentation using [`roxygen2`](https://klutometis.github.io/roxygen/). If you want to improve a function description: +Functions are described as comments near their code and translated to documentation using [`roxygen2`](https://roxygen2.r-lib.org/). If you want to improve a function description: 1. Go to `R/` directory in the [code repository][repo]. 2. Look for the file with the name of the function. @@ -80,8 +88,9 @@ Organise data in R in a [tidy](https://r4ds.had.co.nz/tidy-data.html#tidy-data-1 Recommended resources to get started are: - [R for Data Science](https://r4ds.had.co.nz/) - [Geocomputation with R](https://geocompr.robinlovelace.net) - - [R packages](http://r-pkgs.had.co.nz/) (by Hadley Wickham 2015; an extended/updated [version](https://r-pkgs.org/) is still under development) - - `vignette("formatting", package = "roxygen2")` for documentation syntax + - [R packages](https://r-pkgs.org/) (by Hadley Wickham and Jenny Bryan) + - [`vignette("rd-formatting", package = "roxygen2")`](https://roxygen2.r-lib.org/articles/formatting.html) for documentation syntax. + Or use markdown support in function documentation after adding the `@md` tag. - have a quick look at the [tidyverse style guide](https://style.tidyverse.org/). There you see how to style object, variable and function names, as well as the documentation. At least keep in mind: **use lower case and 'snake_case'** for object, variable and function names. @@ -112,16 +121,67 @@ We try to follow the [GitHub flow](https://guides.github.com/introduction/flow/) #### _With_ write permissions to the [code repository][repo] -More detailed info on git workflows at INBO: . +It is wise to first think about the scope of your function (or your proposed enhancement of an existing one), and talk it through with other collaborators: + +- functions that are of broader interest than Natura 2000, better go to [inborutils](https://inbo.github.io/inborutils/) or a separate package; +- functions that will only be relevant to a specific _watina_ project, are better developed in the project-specific repo. + +You will want to look at the file `src/manage_package.R` to get some useful packaging commands and developing tips. + +**Releases, version numbering and the relation to git branches** + +- We follow the semantic version numbering as described [here](https://r-pkgs.org/description.html#version). +- The commit referred to by `master` (branch tip) must always have a `..` version number in the `DESCRIPTION` file. +It is the latest released package version. + - Subsequent commits on `master` which do not change the package code itself, but only website setup and repo documentation, must inherit the _same_ release version number. + - **Commits which do change the package _must_ carry a development version number**; typically `...9000`. +It follows that they never appear at the tip of the `master` branch. +Non-package commits _may_ follow this route as well: it is safe for all new commits. + + These conventions ensure that: + - a simple package installation with `remotes::install_github()`, which defaults to downloading from the `master` branch, will result in an installation of the latest release; + - the `pkgdown` [website] shows the version number of the latest release. + +- Other branches than `master` can have various names. +However, there is always at least one **development branch** whose name begins with `dev`. +For example: `dev_nextrelease`, `dev_0.4.0`, ... +It is the collector of new features and bugfixes that will lead to a later release, and its first commit should be to add a dev-suffix (`.9000`) to the current version number (don't increment `..`). + - Especially when cooperating, it is counteradvised to push directly to this branch; better do so through pull requests from feature branches. +- Eventually, the development branch's last commit before merging to `master` will be to increment at least one of ``, `` or `` and to drop the dev-suffix from the version number (i.e. in the `DESCRIPTION` file). +Such final commits should happen directly on the development branch. +No later than that commmit (but it can safely be done earlier), also the `.zenodo.json` metadata file must be updated to the new release version number. + + +**Steps and tricks in git** + +The preceding philosophy leads to following steps and guidelines: + +1. Make commits (in your local clone of the remote repo on Github) _in your own git branch_, branched off from the **base** branch you wish to contribute to -- below referred as `` branch. +Let's call your new branch the `` branch. + - In general, the base branch will be a `dev*` branch, or it could be a feature branch of someone else you wish to make a contribution to. + + You can push your branch to the remote as often as you like, as it will not influence other branches (first time: do `git push -u origin yourbranchname`; afterwards `git push` suffices). It serves as a backup and enables others to work with you on that branch. +1. Meanwhile, make sure that your branch stays up to date with evolutions in the base branch. +This is needed to ensure a smooth merge of your branch to the base branch later on. + - To do that in your local repo, you can run `git pull origin ` while having your feature branch checked out. + - If you also wish to update your local base branch in this process, you can first `git checkout ` followed by `git pull`, then switch back to `git checkout ` and merge the base branch with `git merge --no-ff `. + + If any merge conflicts arise at this stage, resolve them in your own branch. +1. Propose to merge your commits into the base branch: after pushing your branch to GitHub (which you can do repeatedly), this starts with making a **pull request** (PR; actually this is a merge request) and assign at least one reviewer before a merge can be decided. +At that moment, open online discussion in the repo is possible on your changes (for other open discussion that you want to start, make an _issue_). +As long as no merge is performed, more commits can be added to this PR with `git push`, e.g. to implement requested changes by others. + - make sure to correctly **set the base branch** in the pull request (because the default is `master`). +1. After your PR is merged, pull the base branch and clean up your local repo in order to keep up with the remote. + +**Git resources** + +- Info on general git workflows at INBO: . See also [these git workshop materials](https://inbo.github.io/git-course/index.html). +- Günther T. (2014). Learn version control with Git: A step-by-step course for the complete beginner. +- +- [Interactive Git cheatsheet](http://ndpsoftware.com/git-cheatsheet.html) + + + -1. Make commits (in your local clone of the remote repo on Github) _in your own git branch_, branched off from the `master` branch. -(But see this in a relative manner: exactly the same process can be repeated by someone else in turn, relative to your branch. -So '`master`' in this protocol can be replaced by another branch name!) -You can push your branch to the remote as often as you like, as it will not influence other branches (first time: do `git push -u origin yourbranchname`; afterwards `git push` suffices). It serves as a backup and enables others to work with you on that branch. -1. Meanwhile, make sure that your branch stays up to date with evolutions in `master` (i.e. in your local repo, update `master` with `git checkout master && git pull` and then, with your own branch checked out again, do `git merge --no-ff master`), in order to prevent merge conflicts with `master` later on. -At this stage, you need to resolve any merge conflicts that may arise in your own branch. -1. Propose to merge your commits into `master`: this starts with making a 'pull request' (PR; actually this is a merge request) and assign at least one reviewer before a merge can be decided. At that moment, open online discussion in the repo is possible on your changes (for other open discussion that you want to start, make an _issue_). As long as no merge is performed, more commits can be added to this PR with `git push`, e.g. to implement requested changes by others. - - note that, if you branched off another (reference) branch than `master`, make sure to change the reference branch in the pull request (the default reference is `master`). -1. After your PR is merged, pull the reference branch (usually `master`) and clean up your local repo in order to keep up with the remote. From 1fcac73fc30a96d210911872fc6daa11c8d5afd7 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Wed, 9 Jun 2021 19:25:57 +0200 Subject: [PATCH 06/15] GHA: update buildignore --- .Rbuildignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 03e6439..74168fb 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -3,10 +3,9 @@ ^LICENSE\.md$ ^README\.Rmd$ ^README-.*\.png$ -.github/ ^docs$ ^_pkgdown\.yml$ ^pkgdown$ -^\.travis\.yml$ ^appveyor\.yml$ ^\.zenodo\.json$ +^\.github$ From 949b08374a7b47b24c9190e9eb93fe12bebbc5a5 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Wed, 9 Jun 2021 19:27:41 +0200 Subject: [PATCH 07/15] Fix some R CMD check notes --- DESCRIPTION | 2 +- R/eval.R | 2 +- man/watina-package.Rd | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 23cba90..ebbb421 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: watina -Title: Querying And Processing Data From The INBO Watina Database +Title: Querying and Processing Data from the INBO Watina Database Version: 0.4.0.9000 Description: The R-package watina contains functions to query and process data from the Watina database at the Research Institute for diff --git a/R/eval.R b/R/eval.R index 87e01e9..e460882 100644 --- a/R/eval.R +++ b/R/eval.R @@ -790,7 +790,7 @@ date, lab_sample_id, chem_variable, value, unit, below_loq." left_join(df2, by = c("loc_code", "chem_variable")) %>% - return + return() } else { return(df1) } diff --git a/man/watina-package.Rd b/man/watina-package.Rd index 6f78edf..5575a6a 100644 --- a/man/watina-package.Rd +++ b/man/watina-package.Rd @@ -4,7 +4,7 @@ \name{watina-package} \alias{watina} \alias{watina-package} -\title{watina: Querying And Processing Data From The INBO Watina Database} +\title{watina: Querying and Processing Data from the INBO Watina Database} \description{ The R-package watina contains functions to query and process data from the Watina database at the Research Institute for From 707abeaa1a8d0a2cc3c017dcfa182a7e2f826b10 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Wed, 9 Jun 2021 19:28:18 +0200 Subject: [PATCH 08/15] Drop dependencies - fixes #82 --- DESCRIPTION | 5 ++--- NAMESPACE | 9 --------- R/cluster.R | 15 +++++++-------- R/get.R | 17 ++++++----------- R/misc.R | 35 +++++++++++++++++++++++++++++++++++ R/sf.R | 9 +++++---- man/require_pkgs.Rd | 24 ++++++++++++++++++++++++ 7 files changed, 79 insertions(+), 35 deletions(-) create mode 100644 R/misc.R create mode 100644 man/require_pkgs.Rd diff --git a/DESCRIPTION b/DESCRIPTION index ebbb421..19f8d2f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,21 +21,20 @@ Depends: R (>= 3.5.0) Imports: assertthat, - dbplyr (>= 1.4.3.9000), dplyr, inbodb, KSgeneral, lubridate, rlang, - sf, stringr, stats, - tibble, tidyr Suggests: knitr, purrr, rmarkdown, + sf, + tibble, tidyselect Remotes: inbo/inbodb diff --git a/NAMESPACE b/NAMESPACE index 035b880..b90e343 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -74,14 +74,6 @@ importFrom(rlang,quo_get_expr) importFrom(rlang,set_names) importFrom(rlang,sym) importFrom(rlang,syms) -importFrom(sf,st_as_sf) -importFrom(sf,st_buffer) -importFrom(sf,st_coordinates) -importFrom(sf,st_crs) -importFrom(sf,st_drop_geometry) -importFrom(sf,st_geometry_type) -importFrom(sf,st_intersects) -importFrom(sf,st_join) importFrom(stats,cutree) importFrom(stats,dist) importFrom(stats,ecdf) @@ -91,7 +83,6 @@ importFrom(stats,sd) importFrom(stats,var) importFrom(stringr,str_c) importFrom(stringr,str_detect) -importFrom(tibble,enframe) importFrom(tidyr,complete) importFrom(tidyr,full_seq) importFrom(tidyr,gather) diff --git a/R/cluster.R b/R/cluster.R index d237372..00969b6 100644 --- a/R/cluster.R +++ b/R/cluster.R @@ -85,9 +85,6 @@ #' } #' #' @export -#' @importFrom sf -#' st_coordinates -#' st_geometry_type #' @importFrom assertthat #' assert_that #' is.string @@ -96,8 +93,6 @@ #' %>% #' as_tibble #' bind_cols -#' @importFrom tibble -#' enframe #' @importFrom stats #' dist #' hclust @@ -111,14 +106,18 @@ cluster_locs <- function(input, assert_that(inherits(input, c("data.frame", "sf"))) assert_that(is.string(xvar), is.string(yvar), is.string(output_var)) + require_pkgs("tibble") + if (inherits(input, "sf")) { - assert_that(unique(st_geometry_type(input)) == "POINT", + require_pkgs("sf") + + assert_that(unique(sf::st_geometry_type(input)) == "POINT", msg = "Geospatial input must only contain POINT geometries.") coords <- input %>% - st_coordinates %>% + sf::st_coordinates() %>% as_tibble xvar <- "X" yvar <- "Y" @@ -146,7 +145,7 @@ cluster_locs <- function(input, dist %>% hclust(method = "complete") %>% cutree(h = max_dist) %>% - enframe(name = NULL, value = output_var) %>% + tibble::enframe(name = NULL, value = output_var) %>% bind_cols(input, .) } diff --git a/R/get.R b/R/get.R index 1d07d08..cf9887f 100644 --- a/R/get.R +++ b/R/get.R @@ -307,12 +307,6 @@ #' is.number #' is.flag #' noNA -#' @importFrom sf -#' st_drop_geometry -#' st_intersects -#' st_crs -#' st_join -#' st_buffer #' @importFrom dplyr #' %>% #' tbl @@ -369,7 +363,8 @@ get_locs <- function(con, if (!is.null(mask)) { assert_that(inherits(mask, "sf"), msg = "mask must be an sf object.") - assert_that(st_crs(mask) == st_crs(31370), + require_pkgs("sf") + assert_that(sf::st_crs(mask) == sf::st_crs(31370), msg = "The CRS of mask must be Belgian Lambert 72 (EPSG-code 31370).") } @@ -640,7 +635,7 @@ get_locs <- function(con, if (buffer != 0) { mask_expand <- mask %>% - st_buffer(dist = buffer) + sf::st_buffer(dist = buffer) } else { mask_expand <- mask @@ -650,16 +645,16 @@ get_locs <- function(con, locs <- locs %>% - st_join(mask_expand, + sf::st_join(mask_expand, left = FALSE) %>% - st_drop_geometry + sf::st_drop_geometry() } else { locs <- locs %>% .[mask_expand, ] %>% - st_drop_geometry + sf::st_drop_geometry() } diff --git a/R/misc.R b/R/misc.R new file mode 100644 index 0000000..6fc1a2c --- /dev/null +++ b/R/misc.R @@ -0,0 +1,35 @@ +#' Check availability of required packages +#' +#' Takes a vector of package names and passes each name to +#' \code{\link[base:ns-load]{requireNamespace()}}; +#' if package(s) are missing, returns an error message providing the basic +#' \code{install.packages()} command to install them. +#' +#' @param pkgs A character vector of package names. +#' +#' @examples +#' \dontrun{ +#' require_pkgs(c("a", "base", "b", "c")) +#' } +#' +#' @importFrom assertthat +#' assert_that +#' @keywords internal +require_pkgs <- function(pkgs) { + assert_that(is.character(pkgs)) + available <- sapply(pkgs, requireNamespace, quietly = TRUE) + if (!all(available)) { + multiple <- sum(!available) > 1 + stop(ifelse(multiple, "Multiple", "A"), + " package", + ifelse(multiple, "s", ""), + " needed for this function ", + ifelse(multiple, "are", "is"), + " missing.\nPlease install as follows: install.packages(", + deparse(pkgs[!available]), + ")", + call. = FALSE) + } +} + + diff --git a/R/sf.R b/R/sf.R index d79da8a..7990cc9 100644 --- a/R/sf.R +++ b/R/sf.R @@ -37,7 +37,6 @@ #' as_points(mydata) #' #' @export -#' @importFrom sf st_as_sf #' @importFrom assertthat #' assert_that #' is.string @@ -57,6 +56,8 @@ as_points <- function(df, assert_that(has_name(df, yvar)) assert_that(is.flag(warn_dupl), noNA(warn_dupl)) + require_pkgs("sf") + df_cleaned <- df[!is.na(df[,xvar]) & !is.na(df[,yvar]),] @@ -71,9 +72,9 @@ as_points <- function(df, } df_cleaned %>% - st_as_sf(coords = c(xvar, yvar), - crs = 31370, - remove = remove) + sf::st_as_sf(coords = c(xvar, yvar), + crs = 31370, + remove = remove) } diff --git a/man/require_pkgs.Rd b/man/require_pkgs.Rd new file mode 100644 index 0000000..98ffff0 --- /dev/null +++ b/man/require_pkgs.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/misc.R +\name{require_pkgs} +\alias{require_pkgs} +\title{Check availability of required packages} +\usage{ +require_pkgs(pkgs) +} +\arguments{ +\item{pkgs}{A character vector of package names.} +} +\description{ +Takes a vector of package names and passes each name to +\code{\link[base:ns-load]{requireNamespace()}}; +if package(s) are missing, returns an error message providing the basic +\code{install.packages()} command to install them. +} +\examples{ +\dontrun{ +require_pkgs(c("a", "base", "b", "c")) +} + +} +\keyword{internal} From f747e8ac9aa39faf362858587592e936ad04e3f6 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Thu, 10 Jun 2021 09:35:04 +0200 Subject: [PATCH 09/15] Readme: drop site-devel badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 108c853..8d01364 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3630532.svg)](https://doi.org/10.5281/zenodo.3630532) [![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing) [![R-CMD-check](https://github.com/inbo/watina/workflows/R-CMD-check/badge.svg)](https://github.com/inbo/watina/actions?query=workflow%3AR-CMD-check) -[![site-devel](https://github.com/inbo/watina/workflows/site-devel/badge.svg)](https://github.com/inbo/watina/actions?query=workflow%3Asite-devel) ## Welcome From 3b6137b333bf1d066d1333d976154a7d2b65bb1d Mon Sep 17 00:00:00 2001 From: florisvdh Date: Thu, 10 Jun 2021 16:48:03 +0200 Subject: [PATCH 10/15] get_xg3(), get_chem(): use DBI to drop pre-existing table * Fixes #85. dbplyr::db_drop_table() does not work anymore. --- DESCRIPTION | 1 + NAMESPACE | 1 - R/get.R | 10 ++++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 19f8d2f..e3f21c0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,6 +30,7 @@ Imports: stats, tidyr Suggests: + DBI, knitr, purrr, rmarkdown, diff --git a/NAMESPACE b/NAMESPACE index b90e343..9f5b575 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -31,7 +31,6 @@ importFrom(dplyr,collect) importFrom(dplyr,contains) importFrom(dplyr,copy_to) importFrom(dplyr,count) -importFrom(dplyr,db_drop_table) importFrom(dplyr,distinct) importFrom(dplyr,filter) importFrom(dplyr,first) diff --git a/R/get.R b/R/get.R index cf9887f..50f727a 100644 --- a/R/get.R +++ b/R/get.R @@ -796,7 +796,6 @@ get_locs <- function(con, #' @importFrom dplyr #' %>% #' copy_to -#' db_drop_table #' filter #' left_join #' inner_join @@ -830,7 +829,9 @@ get_xg3 <- function(locs, locs %>% distinct(.data$loc_code) - try(db_drop_table(con, "##locs"), + require_pkgs("DBI") + + try(DBI::dbRemoveTable(con, "##locs"), silent = TRUE) locs <- @@ -1071,7 +1072,6 @@ get_xg3 <- function(locs, #' @importFrom dplyr #' %>% #' copy_to -#' db_drop_table #' filter #' left_join #' inner_join @@ -1124,7 +1124,9 @@ get_chem <- function(locs, locs %>% distinct(.data$loc_code) - try(db_drop_table(con, "##locs"), + require_pkgs("DBI") + + try(DBI::dbRemoveTable(con, "##locs"), silent = TRUE) locs <- From bc3883507dfd25eb7c4b69788fefb5b48a75b6aa Mon Sep 17 00:00:00 2001 From: florisvdh Date: Thu, 10 Jun 2021 17:44:47 +0200 Subject: [PATCH 11/15] GHA R-CMD-check on macOS: try to solve PROJ issue --- .github/workflows/R-CMD-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 1ca4ad2..5c5bf3e 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -59,9 +59,9 @@ jobs: - name: Install system dependencies (macOS) if: runner.os == 'macOS' run: | - brew install pkg-config brew install udunits brew install gdal + brew install proj - name: Install package dependencies run: | From ce922535d56e68f93901ca3edf54086cc996bf0d Mon Sep 17 00:00:00 2001 From: florisvdh Date: Fri, 11 Jun 2021 09:12:11 +0200 Subject: [PATCH 12/15] GHA R-CMD-check-latest on macOS: try to solve PROJ issue --- .github/workflows/R-CMD-check-latest.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check-latest.yaml b/.github/workflows/R-CMD-check-latest.yaml index df7c164..a719084 100644 --- a/.github/workflows/R-CMD-check-latest.yaml +++ b/.github/workflows/R-CMD-check-latest.yaml @@ -69,9 +69,9 @@ jobs: - name: Install system dependencies (macOS) if: runner.os == 'macOS' run: | - brew install pkg-config brew install udunits brew install gdal + brew install proj - name: Install package dependencies run: | From 08bc66d67ff1e75883178bf3082f616cbb7f3814 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Fri, 11 Jun 2021 14:10:47 +0200 Subject: [PATCH 13/15] get_xg3(), get_chem(): make a local, not a global temporary table * See https://stackoverflow.com/questions/2920836/local-and-global-temporary-tables-in-sql-server/2921091#2921091 This prevents conflicts between multiple connections/users. A global temp table is unneeded so a local one is more appropriate here. --- R/get.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/get.R b/R/get.R index 50f727a..8a6e9b8 100644 --- a/R/get.R +++ b/R/get.R @@ -831,13 +831,13 @@ get_xg3 <- function(locs, require_pkgs("DBI") - try(DBI::dbRemoveTable(con, "##locs"), + try(DBI::dbRemoveTable(con, "#locs"), silent = TRUE) locs <- copy_to(con, locs, - "##locs") %>% + "#locs") %>% inner_join(tbl(con, "vwDimMeetpunt") %>% select(loc_wid = .data$MeetpuntWID, loc_code = .data$MeetpuntCode), @@ -1126,13 +1126,13 @@ get_chem <- function(locs, require_pkgs("DBI") - try(DBI::dbRemoveTable(con, "##locs"), + try(DBI::dbRemoveTable(con, "#locs"), silent = TRUE) locs <- copy_to(con, locs, - "##locs") %>% + "#locs") %>% inner_join(tbl(con, "vwDimMeetpunt") %>% select(loc_wid = .data$MeetpuntWID, loc_code = .data$MeetpuntCode), From c9f5798a4c68151662647debec06eee2c6db9fa6 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Fri, 11 Jun 2021 14:30:04 +0200 Subject: [PATCH 14/15] NEWS; .zenodo.json: prepare for version 0.4.1 --- .zenodo.json | 2 +- NEWS.md | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.zenodo.json b/.zenodo.json index 70fa8db..c7911f2 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -4,7 +4,7 @@ "license": "GPL-3.0", "upload_type": "software", "access_right": "open", - "version": "0.4.0", + "version": "0.4.1", "creators": [ { "name": "Vanderhaeghe, Floris", diff --git a/NEWS.md b/NEWS.md index 4d46f7c..716b1c6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# watina 0.4.1 (2021-06-11) + +- Fixed non-working `get_xg3()` and `get_chem()` for dataframe input, by avoiding the currently defunct `dbplyr::db_drop_table()` (#89, [08bc66d](https://github.com/inbo/watina/commit/08bc66d)). +- Various maintenance (#81, #86, #87, #88, [c382499](https://github.com/inbo/watina/commit/c382499)). + # watina 0.4.0 (2021-01-18) - This release has been made compatible with `dbplyr` 2.0.0 (on CRAN); the `dbplyr` fork is not needed anymore ([e66e58f](https://github.com/inbo/watina/commit/e66e58f), #74). From 38cdb90347019c569896f083855e9bdd7b44d2d8 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Fri, 11 Jun 2021 14:31:29 +0200 Subject: [PATCH 15/15] Description: bump version to 0.4.1 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index e3f21c0..7496e8d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: watina Title: Querying and Processing Data from the INBO Watina Database -Version: 0.4.0.9000 +Version: 0.4.1 Description: The R-package watina contains functions to query and process data from the Watina database at the Research Institute for Nature and Forest (INBO). This database primarily provides