Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 43 additions & 18 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,74 @@
name: build

on:
push:
branches: [main, k_dev]
pull_request:
branches: [main, k_dev]

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
GITHUB_PAT: ${{ secrets.GH_RHAP_TOKEN}}

steps:
- uses: actions/checkout@v1
- uses: r-lib/actions/setup-r@v2-branch
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
r-version: '4.1'
- uses: r-lib/actions/setup-pandoc@v2-branch
- uses: r-lib/actions/setup-tinytex@v2-branch
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@v2

- name: Install libraries
- uses: r-lib/actions/setup-tinytex@v2

- name: Install system libraries
if: startsWith(matrix.config.os, 'ubuntu')
run: |
sudo apt-add-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install -y libcurl4-openssl-dev libssl-dev libxml2-dev libudunits2-dev libgdal-dev libgeos-dev libproj-dev libmagick++-dev libavfilter-dev libharfbuzz-dev libfribidi-dev
sudo apt-get install -y \
libcurl4-openssl-dev libssl-dev libxml2-dev \
libudunits2-dev libgdal-dev libgeos-dev libproj-dev \
libmagick++-dev libavfilter-dev \
libharfbuzz-dev libfribidi-dev \
libfontconfig1-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev \
libuv1-dev

- name: Install dependencies
- name: Install R dependencies
run: |
install.packages(c("remotes","rcmdcheck","stringi"), repos = "https://cloud.r-project.org")
install.packages(c("evaluate"), repos = "https://cloud.r-project.org")
install.packages(c("knitr","rmarkdown","htmlwidgets", "plm"), repos = "https://cloud.r-project.org")
remotes::install_deps(dependencies = TRUE)
options(Ncpus = parallel::detectCores())
options(repos = c(CRAN = "https://cloud.r-project.org"))
install.packages(c("remotes", "rcmdcheck", "covr", "fs", "usethis", "testthat")
remotes::install_deps(dependencies = TRUE, upgrade = "never")
shell: Rscript {0}

- name: Install the package
run: remotes::install_local(".")
shell: Rscript {0}

# - name: Install dependencies
# run: |
# install.packages(c("remotes", "rcmdcheck", "stringi", "devtools"), repos = "https://cloud.r-project.org")
# install.packages(c("evaluate"), repos = "https://cloud.r-project.org")
# install.packages(c("knitr", "rmarkdown", "htmlwidgets", "plm"), repos = "https://cloud.r-project.org")
# remotes::install_deps(dependencies = TRUE)
# shell: Rscript {0}
#
# - name: Install GitHub packages
# run: |
# remotes::install_github("JGCRI/rmap")
# remotes::install_github("JGCRI/gcamdata")
# shell: Rscript {0}

- name: Check
run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--ignore-vignettes", "--no-build-vignettes"), build_args = c("--no-manual", "--ignore-vignettes", "--no-build-vignettes"), error_on = "error")
shell: Rscript {0}

- name: Run tests
run: testthat::test()
shell: Rscript {0}
26 changes: 12 additions & 14 deletions .github/workflows/test_coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
name: test_coverage

on:
push:
branches: [main]
pull_request:
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" }

- { os: ubuntu-latest, r: 'release' }
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GH_RHAP_TOKEN }}

steps:
- uses: actions/checkout@v4

Expand All @@ -29,27 +24,31 @@ jobs:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-tinytex@v2

- name: Install system libraries
if: startsWith(matrix.config.os, 'ubuntu')
run: |
sudo apt-add-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install -y \
libcurl4-openssl-dev libssl-dev libxml2-dev \
libudunits2-dev libgdal-dev libgeos-dev libproj-dev \
libmagick++-dev libavfilter-dev libharfbuzz-dev libfribidi-dev
libmagick++-dev libavfilter-dev \
libharfbuzz-dev libfribidi-dev \
libfontconfig1-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev \
libuv1-dev

- name: Install R dependencies
run: |
install.packages(c("remotes", "rcmdcheck", "covr"), repos = "https://cloud.r-project.org")
remotes::install_deps(dependencies = TRUE)
options(Ncpus = parallel::detectCores())
options(repos = c(CRAN = "https://cloud.r-project.org"))
install.packages(c("remotes", "rcmdcheck", "covr", "fs", "usethis", "testthat")
remotes::install_deps(dependencies = TRUE, upgrade = "never")
shell: Rscript {0}

- name: Install the package
run: |
remotes::install_local(".")
run: remotes::install_local(".")
shell: Rscript {0}

- name: Run tests and generate coverage
Expand All @@ -60,7 +59,6 @@ jobs:

- uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }} # Optional if repo is public
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
verbose: true

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ R/*.txt
/tests/testthat/testInputs/database_basexdb_ref/*
/tests/testthat/output
inst/doc
/output_esp
plot*
*pptx
*check*
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Depends: R (>= 3.5)
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
Imports:
usethis,
ggplot2,
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

export(calc_ResidEm_grp)
export(calc_hap_impacts)
export(calc_hap_impacts_predict)
export(calc_hap_impacts_preprocess)
export(calc_hia_adder)
export(create_panel)
export(fit_model)
export(get_gdp_ctry)
export(get_pop_ctry)
export(listYears)
importFrom(magrittr,"%>%")
50 changes: 29 additions & 21 deletions R/calc_ResidEm_grp.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,6 @@ calc_ResidEm_grp <- function(db_path = NULL, query_path = "./inst/extdata", db_n
if (length(pollutant) != 1) stop("Error: Please provide a single pollutant as input to the `calc_ResidEm_grp` function.")
if (length(region) != 1) stop("Error: Please provide a single region as input to the `calc_ResidEm_grp` function.")

year <- as.numeric(as.character(year))
if (!year %in% seq(2020, 2100, 5)) {
stop(sprintf(
"Error: The specified year '%s' is invalid. Accepted years are: %s. Please rerun the `calc_ResidEm_grp` function with a valid year.",
year, paste(seq(2020, 2100, 5), collapse = ", ")
))
}
if (!pollutant %in% rhap::all_pollutants) {
stop(sprintf(
"Error: The specified pollutant '%s' is invalid. Accepted pollutants are: %s. Please rerun the `calc_ResidEm_grp` function with a valid pollutant.",
pollutant, paste(rhap::all_pollutants, collapse = ", ")
))
}
if (!region %in% rhap::gcam_regions) {
stop(sprintf(
"Error: The specified region '%s' is invalid. Accepted regions are: %s. Please rerun the `calc_ResidEm_grp` function with a valid region.",
region, paste(rhap::gcam_regions, collapse = ", ")
))
}


# Then, load the rgcam project if prj not passed as a parameter:
if (!is.null(db_path) & !is.null(db_name)) {
Expand All @@ -79,11 +59,39 @@ calc_ResidEm_grp <- function(db_path = NULL, query_path = "./inst/extdata", db_n
final_db_year,
max(rgcam::getQuery(prj, "nonCO2 emissions by sector (excluding resource production)")$year)
)
# Find last historical year
years_in_prj <- listYears(prj)
years_in_prj <- years_in_prj[!is.na(years_in_prj)]
years_in_prj <- setdiff(years_in_prj, NA)
base_year <- dplyr::if_else(2021 %in% years_in_prj, 2021, 2015)
base_year_p <- dplyr::if_else(base_year == 2021, base_year, 2020)

# More checks
year <- as.numeric(as.character(year))
if (!year %in% c(base_year_p, seq(2025, 2100, 5))) {
stop(sprintf(
"Error: The specified year '%s' is invalid. Accepted years are: %s. Please rerun the `calc_ResidEm_grp` function with a valid year.",
year, paste(c(base_year_p, seq(2025, 2100, 5)), collapse = ", ")
))
}
if (!pollutant %in% rhap::all_pollutants) {
stop(sprintf(
"Error: The specified pollutant '%s' is invalid. Accepted pollutants are: %s. Please rerun the `calc_ResidEm_grp` function with a valid pollutant.",
pollutant, paste(rhap::all_pollutants, collapse = ", ")
))
}
if (!region %in% rhap::gcam_regions) {
stop(sprintf(
"Error: The specified region '%s' is invalid. Accepted regions are: %s. Please rerun the `calc_ResidEm_grp` function with a valid region.",
region, paste(rhap::gcam_regions, collapse = ", ")
))
}


if (year > final_db_year) {
stop(sprintf(
"Error: The specified year '%s' is invalid. The database only contains data up to %s. Accepted years are: %s. Please rerun the `calc_ResidEm_grp` function with a valid year.",
year, final_db_year, paste(seq(2020, final_db_year, 5), collapse = ", ")
year, final_db_year, paste(c(base_year_p, seq(2025, final_db_year, 5)), collapse = ", ")
))
}

Expand Down
Loading
Loading