Skip to content

Commit

Permalink
Merge pull request #74 from johanneskoch94/main
Browse files Browse the repository at this point in the history
Fix spikes in SSP2EU pop scenarios
  • Loading branch information
johanneskoch94 authored Aug 18, 2023
2 parents 38aea89 + c221251 commit 91f0eef
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '2541630'
ValidationKey: '2742180'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
92 changes: 21 additions & 71 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Run CI for R using https://eddelbuettel.github.io/r-ci/

name: check

on:
Expand All @@ -8,92 +6,44 @@ on:
pull_request:
branches: [main, master]

env:
USE_BSPM: "true"
_R_CHECK_FORCE_SUGGESTS_: "false"
NO_BINARY_INSTALL_R_PACKAGES: 'c("madrat", "magclass", "citation", "gms", "goxygen", "GDPuc", "roxygen2")'

jobs:
check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Bootstrap
run: |
sudo chown runner -R .
sudo locale-gen en_US.UTF-8
sudo add-apt-repository -y ppa:ubuntugis/ppa
curl -OLs https://eddelbuettel.github.io/r-ci/run.sh
chmod 0755 run.sh
./run.sh bootstrap
rm -f bspm_*.tar.gz
- name: Enable r-universe repo, modify bspm integration
run: |
# install packages from https://pik-piam.r-universe.dev and CRAN
echo '
options(repos = c(universe = "https://pik-piam.r-universe.dev",
CRAN = "https://cloud.r-project.org"))
' >> .Rprofile
cat .Rprofile
# modify bspm integration to never install binary builds of PIK CRAN packages
sudo sed -i '/bspm::enable()/d' /etc/R/Rprofile.site
# need double % because of printf, %s is replaced with "$NO_BINARY_INSTALL_R_PACKAGES" (see "env:" above)
printf '
local({
expr <- quote({
if (!is.null(repos)) {
noBinaryInstallRPackages <- %s
pkgs <- c(bspm::install_sys(pkgs[!pkgs %%in%% noBinaryInstallRPackages]),
pkgs[pkgs %%in%% noBinaryInstallRPackages])
}
type <- "source"
})
trace(utils::install.packages, expr, print = FALSE)
})
' "$NO_BINARY_INSTALL_R_PACKAGES" | sudo tee --append /etc/R/Rprofile.site >/dev/null
cat /etc/R/Rprofile.site
- name: Set up Pandoc
uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-pandoc@v2

- name: Set up Python 3.9
uses: actions/setup-python@v4
- uses: r-lib/actions/setup-r@v2
with:
python-version: 3.9
use-public-rspm: true
extra-repositories: "https://rse.pik-potsdam.de/r/packages"

- name: Cache R libraries
if: ${{ !env.ACT }} # skip when running locally via nektos/act
uses: pat-s/always-upload-cache@v3
- uses: r-lib/actions/setup-r-dependencies@v2
with:
path: /usr/local/lib/R/
key: 3-${{ runner.os }}-usr-local-lib-R-${{ hashFiles('DESCRIPTION') }}
restore-keys: |
3-${{ runner.os }}-usr-local-lib-R-
- name: Restore R library permissions
run: |
sudo chmod 2777 /usr/local/lib/R /usr/local/lib/R/site-library
- name: Install dependencies
run: |
./run.sh install_aptget libhdf5-dev libharfbuzz-dev libfribidi-dev
./run.sh install_all
./run.sh install_r_binary covr rstudioapi
./run.sh install_r lucode2
extra-packages: |
any::lucode2
any::covr
any::madrat
any::magclass
any::citation
any::gms
any::goxygen
any::GDPuc
# piam packages also available on CRAN (madrat, magclass, citation,
# gms, goxygen, GDPuc) will usually have an outdated binary version
# available; by using extra-packages we get the newest version

- uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Install python dependencies if applicable
run: |
[ -f requirements.txt ] && python -m pip install --upgrade pip wheel || true
[ -f requirements.txt ] && pip install -r requirements.txt || true
- name: Remove bspm integration # to get rid of error when running install.packages
run: |
sudo sed -i '/ trace(utils::install.packages, expr, print = FALSE)/d' /etc/R/Rprofile.site
cat /etc/R/Rprofile.site
- name: Verify validation key
shell: Rscript {0}
run: lucode2:::validkey(stopIfInvalid = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/lorenzwalthert/precommit
rev: v0.3.2.9013
rev: v0.3.2.9019
hooks:
- id: parsable-R
- id: deps-in-desc
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'mrdrivers: Create GDP and Population Scenarios'
version: 1.3.0
date-released: '2023-07-13'
version: 1.4.0
date-released: '2023-08-18'
abstract: Create GDP and population scenarios This package constructs the GDP and
population scenarios used as drivers in both the REMIND and MAgPIE models.
authors:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mrdrivers
Type: Package
Title: Create GDP and Population Scenarios
Version: 1.3.0
Version: 1.4.0
Authors@R: c(person(given = "Johannes",
family = "Koch",
email = "[email protected]",
Expand Down Expand Up @@ -49,6 +49,6 @@ Suggests:
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Date: 2023-07-13
Date: 2023-08-18
Config/testthat/edition: 3
VignetteBuilder: knitr
11 changes: 5 additions & 6 deletions R/calcPopulationHarmonized.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ toolHarmonizeWithPEAPandFuture <- function(past, future) {
toolHarmonizeSSP2EU <- function(past, future) {
harmonizedData <- toolHarmonizeWithPEAPandFuture(past, future)

# For SSP2EU: simply glue past (until 2019) with future (starting 2020)
# Get EUR countries.
# For EUR countries use only growth rates of EUROSTAT projections (load in fresh: future only has 5 year steps)
euCountries <- toolGetEUcountries()

futYears <- getYears(future$x)[getYears(future$x, as.integer = TRUE) >= 2020]
harmonizedData$x[euCountries, futYears, ] <- future$x[euCountries, futYears, ]
dataEurostat <- readSource("EurostatPopGDP", "population_projections") * 1e-6
x <- toolHarmonizePastGrFuture(past$x[euCountries, , ], dataEurostat[euCountries, , ])
harmonizedData$x[euCountries, , ] <- x[euCountries, getYears(harmonizedData$x), ]

list(x = harmonizedData$x,
description = glue("{harmonizedData$description} For European countries, just glue past with future."))
description = glue("{harmonizedData$description} For European countries, just use future growth rates."))
}

toolHarmonizeISIMIP <- function(past, future, yEnd) {
Expand Down
2 changes: 1 addition & 1 deletion R/readEurostatPopGDP.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ convEurostatPopulation <- function(x) {
getNames(x) <- "population"
# Use the "DE_TOT" values for Germany, if they exist (DE_TOT = East + West Germany)
x["DE", , ] <- if ("DE_TOT" %in% getItems(x, 1)) x["DE_TOT", , ] else x["DE", , ]
# Drop any countries with more than 2 charachters in their Eurostat identifier. Those are aggregates.
# Drop any countries with more than 2 characters in their Eurostat identifier. Those are aggregates.
myCountries <- getItems(x, 1)[purrr::map_lgl(getItems(x, 1), ~ nchar(.x) == 2)]
x <- x[myCountries, , ]
# Convert the eurostat countrycodes to iso3c codes
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Create GDP and Population Scenarios

R package **mrdrivers**, version **1.3.0**
R package **mrdrivers**, version **1.4.0**

[![CRAN status](https://www.r-pkg.org/badges/version/mrdrivers)](https://cran.r-project.org/package=mrdrivers) [![R build status](https://pik-piam.github.io/mrdrivers/workflows/check/badge.svg)](https://pik-piam.github.io/mrdrivers/actions) [![codecov](https://codecov.io/gh/mrdrivers/branch/master/graph/badge.svg)](https://app.codecov.io/gh/mrdrivers) [![r-universe](https://pik-piam.r-universe.dev/badges/mrdrivers)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -103,7 +103,7 @@ In case of questions / problems please contact Johannes Koch <jokoch@pik-potsdam

To cite package **mrdrivers** in publications use:

Koch J, Soergel B, Leip D, Benke F, Dietrich J (2023). _mrdrivers: Create GDP and Population Scenarios_. R package version 1.3.0, <https://pik-piam.github.io/mrdrivershttps://github.com/pik-piam/mrdrivers>.
Koch J, Soergel B, Leip D, Benke F, Dietrich J (2023). _mrdrivers: Create GDP and Population Scenarios_. R package version 1.4.0, <https://pik-piam.github.io/mrdrivershttps://github.com/pik-piam/mrdrivers>.

A BibTeX entry for LaTeX users is

Expand All @@ -112,7 +112,7 @@ A BibTeX entry for LaTeX users is
title = {mrdrivers: Create GDP and Population Scenarios},
author = {Johannes Koch and Bjoern Soergel and Deborra Leip and Falk Benke and Jan Philipp Dietrich},
year = {2023},
note = {R package version 1.3.0},
note = {R package version 1.4.0},
url = {https://pik-piam.github.io/mrdrivers},
url = {https://github.com/pik-piam/mrdrivers},
}
Expand Down

0 comments on commit 91f0eef

Please sign in to comment.