diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..1cc3986 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,51 @@ +name: R-CMD-check + +on: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: read-all + +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: '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.PAT }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v4 + + - 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 + build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' + error-on: '"error"' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 08ba915..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: build - -on: - push: - branches: - - main - -jobs: - R-CMD: - runs-on: ${{ matrix.config.os }} - - name: ${{ matrix.config.os }} (${{ matrix.config.r }}) - - strategy: - fail-fast: false - matrix: - config: - - { os: ubuntu-latest, r: 'devel', cran: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"} - - env: - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - RSPM: ${{ matrix.config.rspm }} - GITHUB_PAT: ${{ secrets.PAT}} - - steps: - - uses: actions/checkout@v3 - - uses: r-lib/actions/setup-r@v2-branch - with: - r-version: '3.6' - - uses: r-lib/actions/setup-pandoc@v2-branch - - uses: r-lib/actions/setup-tinytex@v2-branch - - - name: Cache R packages - uses: actions/cache@v3 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Ubuntu config - run: | - sudo add-apt-repository ppa:ubuntugis/ppa - sudo apt-get update - sudo apt-get install -y libudunits2-dev libgdal-dev libgeos-dev libproj-dev libmagick++-dev - - - name: MacOS Config - if: startsWith(matrix.config.os, 'macOS') - run: | - brew install pkg-config - brew install gdal - - - name: Install dependencies - run: | - install.packages(c("remotes", "rcmdcheck"), repos = "https://cloud.r-project.org") - remotes::install_deps(dependencies = TRUE) - shell: Rscript {0} - - - name: Check - run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "error") - shell: Rscript {0} diff --git a/.github/workflows/test_coverage.yaml b/.github/workflows/test_coverage.yaml new file mode 100644 index 0000000..eedb178 --- /dev/null +++ b/.github/workflows/test_coverage.yaml @@ -0,0 +1,60 @@ +name: test_coverage + +on: + push: + branches: [main] + pull_request: + branches: [main] + +permissions: read-all + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.PAT }} + + + steps: + - uses: actions/checkout@v4 + + - 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, any::xml2 + needs: coverage + + - name: Test coverage + run: | + cov <- covr::package_coverage( + quiet = FALSE, + clean = FALSE, + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") + ) + covr::to_cobertura(cov) + shell: Rscript {0} + + - uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }} + file: ./cobertura.xml + plugin: noop + disable_search: true + token: ${{ secrets.CODECOV_TOKEN }} + + - 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@v4 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/.github/workflows/test_coverage.yml b/.github/workflows/test_coverage.yml deleted file mode 100644 index ab8af80..0000000 --- a/.github/workflows/test_coverage.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: test_coverage - -on: - push: - branches: - - main - -jobs: - build: - runs-on: ubuntu-latest - - env: - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - GITHUB_PAT: ${{ secrets.PAT}} - - steps: - - uses: actions/checkout@v3 - - uses: r-lib/actions/setup-r@v2-branch - with: - r-version: '3.6' - - uses: r-lib/actions/setup-pandoc@v2-branch - - uses: r-lib/actions/setup-tinytex@v2-branch - - - name: Cache R packages - uses: actions/cache@v3 - with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Ubuntu config - run: | - sudo add-apt-repository ppa:ubuntugis/ppa - sudo apt-get update - sudo apt-get install -y libudunits2-dev libgdal-dev libgeos-dev libproj-dev libmagick++-dev - - - name: Install dependencies - run: | - install.packages(c("remotes","rcmdcheck"), repos = "https://cloud.r-project.org") - remotes::install_deps(dependencies = TRUE, upgrade = "never") - shell: Rscript {0} - - - name: Test coverage - run: | - remotes::install_cran("covr") - covr::codecov(token = "${{secrets.CODECOV_TOKEN}}") - shell: Rscript {0} - - - name: Check for failures - if: failure() - run: exit 1 diff --git a/R/hdcd.R b/R/hdcd.R index 64fff14..6a80776 100644 --- a/R/hdcd.R +++ b/R/hdcd.R @@ -203,6 +203,8 @@ hdcd <- function(ncdf = NULL, print('Starting population weighting ...') population_j_weighted <- population_j_grid %>% + dplyr::filter(lat %in% grid_intersect$lat, + lon %in% grid_intersect$lon) %>% dplyr::group_by(region, ID, subRegion, year) %>% dplyr::mutate(subRegion_total_value = sum(value, na.rm = T), value = ifelse(is.na(value), 0, value)) %>% @@ -221,8 +223,9 @@ hdcd <- function(ncdf = NULL, dplyr::left_join(population_j_weighted %>% dplyr::select(-value, -subRegion_total_value), by = c('ID', 'region', 'subRegion', 'lat', 'lon', 'year')) %>% - dplyr::mutate(value = (((value - 273.15) * 9/5) + 32) - reference_temp_F, - value = dplyr::if_else(is.na(pop_weight), value, value * pop_weight)) + dplyr::mutate(pop_weight = ifelse(is.na(pop_weight), 0, pop_weight), + value = (((value - 273.15) * 9/5) + 32) - reference_temp_F, + value = value * pop_weight) } else { print(paste0('Population data years: ', paste(names(population_j_grid)[!grepl('RID|lat|lon', names(population_j_grid))], collapse = ','))) @@ -246,13 +249,10 @@ hdcd <- function(ncdf = NULL, hdcd_region <- ncdf_hdcd_pop_weighted %>% dplyr::filter(!is.na(subRegion)) %>% dplyr::select(-lat, -lon) %>% - dplyr::group_by(region, subRegion, ID, year, datetime) %>% - dplyr::summarise(value = dplyr::if_else(any(is.na(pop_weight)), mean(value), sum(value))) %>% - dplyr::ungroup() - - # Assign HDCD categories - hdcd_region <- hdcd_region %>% dplyr::mutate(HDCD = dplyr::if_else(value < 0, 'HD', 'CD')) %>% + dplyr::group_by(region, subRegion, ID, year, datetime, HDCD) %>% + dplyr::summarise(value = sum(value)) %>% + dplyr::ungroup() %>% dplyr::filter(value != 0) #...................... diff --git a/README.md b/README.md index 35063bd..aba0efa 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ -[![build](https://github.com/JGCRI/helios/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/JGCRI/helios/actions/workflows/build.yml) -[![test_coverage](https://github.com/JGCRI/helios/actions/workflows/test_coverage.yml/badge.svg?branch=main)](https://github.com/JGCRI/helios/actions/workflows/test_coverage.yml) +[![R-CMD-check](https://github.com/JGCRI/helios/actions/workflows/R-CDM-check.yaml/badge.svg?branch=main)](https://github.com/JGCRI/helios/actions/workflows/R-CDM-check.yaml) +[![test-coverage](https://github.com/JGCRI/helios/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/JGCRI/helios/actions/workflows/test-coverage.yaml) [![docs](https://github.com/JGCRI/helios/actions/workflows/docs.yaml/badge.svg?branch=main)](https://github.com/JGCRI/helios/actions/workflows/docs.yaml) [![codecov](https://codecov.io/gh/JGCRI/helios/branch/main/graph/badge.svg?token=XQ913U4IYM)](https://codecov.io/gh/JGCRI/helios) -[![Github All Releases](https://img.shields.io/github/downloads/JGCRI/helios/total.svg)]() [![DOI](https://joss.theoj.org/papers/10.21105/joss.06033/status.svg)](https://doi.org/10.21105/joss.06033) [![DOI](https://zenodo.org/badge/429143355.svg)](https://zenodo.org/doi/10.5281/zenodo.8170310)