From a886737d85f4878d04f2a7adf675099bc125b840 Mon Sep 17 00:00:00 2001 From: Johannes Koch Date: Fri, 15 Dec 2023 18:45:17 +0100 Subject: [PATCH] Bump version with lucode2 and fix linter warnings --- .buildlibrary | 2 +- .github/workflows/check.yaml | 5 ++++- .pre-commit-config.yaml | 4 ++-- CITATION.cff | 4 ++-- DESCRIPTION | 4 ++-- R/calcGDPFuture.R | 16 ++++++++-------- R/calcGDPHarmonized.R | 10 +++++----- R/calcPopulationFuture.R | 3 ++- R/readIMF.R | 6 +++--- R/readUN_PopDiv.R | 4 ++-- R/toolExtend2150.R | 6 +++--- R/toolGetEUcountries.R | 2 +- R/toolReduce.R | 12 +++++++----- README.md | 6 +++--- 14 files changed, 45 insertions(+), 39 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index b751bb4..8ad7c82 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '2742180' +ValidationKey: '2955900' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 7d564a1..870f216 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -23,6 +23,7 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: | + gamstransfer=?ignore any::lucode2 any::covr any::madrat @@ -56,6 +57,8 @@ jobs: - name: Test coverage shell: Rscript {0} - run: covr::codecov(quiet = FALSE) + run: | + nonDummyTests <- setdiff(list.files("./tests/testthat/"), c("test-dummy.R", "_snaps")) + if(length(nonDummyTests) > 0) covr::codecov(quiet = FALSE) env: NOT_CRAN: "true" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5d2e4ca..2f13466 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ exclude: '^tests/testthat/_snaps/.*$' repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-case-conflict - id: check-json @@ -15,7 +15,7 @@ repos: - id: mixed-line-ending - repo: https://github.com/lorenzwalthert/precommit - rev: v0.3.2.9019 + rev: v0.3.2.9025 hooks: - id: parsable-R - id: deps-in-desc diff --git a/CITATION.cff b/CITATION.cff index 64a9feb..795b8fd 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -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.4.0 -date-released: '2023-08-18' +version: 1.5.0 +date-released: '2023-12-15' 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: diff --git a/DESCRIPTION b/DESCRIPTION index 4864053..4cd8afa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: mrdrivers Type: Package Title: Create GDP and Population Scenarios -Version: 1.4.0 +Version: 1.5.0 Authors@R: c(person(given = "Johannes", family = "Koch", email = "jokoch@pik-potsdam.de", @@ -48,6 +48,6 @@ Suggests: Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 -Date: 2023-08-18 +Date: 2023-12-15 Config/testthat/edition: 3 VignetteBuilder: knitr diff --git a/R/calcGDPFuture.R b/R/calcGDPFuture.R index a071e85..b7feab8 100644 --- a/R/calcGDPFuture.R +++ b/R/calcGDPFuture.R @@ -76,7 +76,7 @@ calcInternalGDPFutureSSPs <- function(unit) { GDPuc::convertGDP("constant 2005 Int$PPP", unit, replace_NAs = c("linear", "no_conversion")) y2 <- getYears(data2005PPP)[getYears(data2005PPP, as.integer = TRUE) > c15 & - getYears(data2005PPP, as.integer = TRUE) < 2100] + getYears(data2005PPP, as.integer = TRUE) < 2100] dataFarFut <- data2005PPP[, y2, ] * NA # Convert to 2017 Int$PPP using the 2017 value of base 2005 GDP deflator @@ -86,14 +86,14 @@ calcInternalGDPFutureSSPs <- function(unit) { data2017PPP <- mbind(dataNearFut, dataFarFut, data2100) - q <- data2005PPP / data2017PPP + ratio <- data2005PPP / data2017PPP # For interpolation to work, the last and first values have to be non-NA/non-NaN - q[, 2100, ][is.na(q[, 2100, ])] <- 0 + ratio[, 2100, ][is.na(ratio[, 2100, ])] <- 0 # The first 2 years of the SSP data set are incomplete. For countries that only lack data in these first 2 years, # set NaN to 0. - q[, 2000, ][is.nan(q[, 2000, ]) & !is.nan(q[, 2010, ])] <- 0 + ratio[, 2000, ][is.nan(ratio[, 2000, ]) & !is.nan(ratio[, 2010, ])] <- 0 - q <- as.data.frame(q, rev = 2) %>% + ratio <- as.data.frame(ratio, rev = 2) %>% dplyr::rename("value" = ".value") %>% dplyr::arrange(.data$year) %>% dplyr::group_by(.data$iso3c, .data$variable) %>% @@ -101,7 +101,7 @@ calcInternalGDPFutureSSPs <- function(unit) { dplyr::ungroup() %>% as.magpie(tidy = TRUE) - data2017PPP <- data2005PPP / q + data2017PPP <- data2005PPP / ratio data2017PPP[is.na(data2017PPP)] <- data2005PPP[is.na(data2017PPP)] # Above should probably be "<- 0" ################## @@ -110,7 +110,7 @@ calcInternalGDPFutureSSPs <- function(unit) { # If unit was in $MER if (constructUnit != unit) { - data <- GDPuc::convertGDP(data, constructUnit, unit, replace_NAs = c("linear", "no_conversion")) + data <- GDPuc::convertGDP(data, constructUnit, unit, replace_NAs = c("linear", "no_conversion")) } list(x = data, weight = NULL, unit = glue("mil. {unit}"), description = "SSP projections") @@ -128,7 +128,7 @@ calcInternalGDPFutureSDPs <- function(unit) { calcInternalGDPFutureSSP2EU <- function(unit) { dataSSP2EU <- readSource("ARIADNE", "gdp_corona") %>% - GDPuc::convertGDP("constant 2005 Int$PPP", unit, replace_NAs = c("linear", "no_conversion")) + GDPuc::convertGDP("constant 2005 Int$PPP", unit, replace_NAs = c("linear", "no_conversion")) dataSSP <- calcOutput("InternalGDPFutureSSPs", unit = unit, aggregate = FALSE) # Get EU-27 countries diff --git a/R/calcGDPHarmonized.R b/R/calcGDPHarmonized.R index a861903..ab256d5 100644 --- a/R/calcGDPHarmonized.R +++ b/R/calcGDPHarmonized.R @@ -78,9 +78,9 @@ toolGDPHarmonizeSSP2EU <- function(past, future, unit) { combined <- combined[, getYears(combined)[getYears(combined, as.integer = TRUE) <= 2100], ] list(x = combined, - description = glue("equal to SSP2 in all countries except for EU countries. \\ - For EU countries use {past$description} until 2021, \\ - growth rates from Eurostat until 2024, \\ - growth rates from {future$description} until 2070, \\ - and converge to 2150 (bezier-extended) SSP2 values thereafter.")) + description = glue("equal to SSP2 in all countries except for EU countries. \\ + For EU countries use {past$description} until 2021, \\ + growth rates from Eurostat until 2024, \\ + growth rates from {future$description} until 2070, \\ + and converge to 2150 (bezier-extended) SSP2 values thereafter.")) } diff --git a/R/calcPopulationFuture.R b/R/calcPopulationFuture.R index 7c25847..7394879 100644 --- a/R/calcPopulationFuture.R +++ b/R/calcPopulationFuture.R @@ -32,7 +32,8 @@ calcInternalPopulationFuture <- function(PopulationFuture) { # nolint "UN_PopDiv" = calcOutput("InternalPopulationFutureUN_PopDiv", aggregate = FALSE, supplementary = TRUE), "MI" = calcOutput("InternalPopMI", aggregate = FALSE, supplementary = TRUE), "SSPsOld" = calcOutput("InternalPopulationFutureSSPsOld", aggregate = FALSE, supplementary = TRUE), - stop("Bad input for PopulationFuture. Invalid 'PopulationFuture' argument.")) + stop("Bad input for PopulationFuture. Invalid 'PopulationFuture' argument.") + ) data$x <- toolFinishingTouches(data$x) data diff --git a/R/readIMF.R b/R/readIMF.R index 93db444..c8df095 100644 --- a/R/readIMF.R +++ b/R/readIMF.R @@ -34,9 +34,9 @@ readIMF <- function(subtype = "current_account", subset = "WEOOct2022all.xls") { dplyr::mutate(value = gsub(",", "", .data$value), dplyr::across(.cols = c("year", "value"), ~ suppressWarnings(as.double(.x))), - # The warnings that are being suppressed above, come from - # character strings that can't be converted to numeric, and - # are thus returned as NA. + # The warnings that are being suppressed above, come from + # character strings that can't be converted to numeric, and + # are thus returned as NA. value = tidyr::replace_na(.data$value, 0)) %>% tidyr::pivot_wider(names_from = "Subject Descriptor") diff --git a/R/readUN_PopDiv.R b/R/readUN_PopDiv.R index 258662b..8e5842f 100644 --- a/R/readUN_PopDiv.R +++ b/R/readUN_PopDiv.R @@ -29,14 +29,14 @@ readUN_PopDiv <- function(subtype = "estimates") { # nolint #' @rdname readUN_PopDiv #' @order 3 #' @param x MAgPIE object returned from readUN_PopDiv -convertUN_PopDiv <- function(x) { +convertUN_PopDiv <- function(x) { # nolint toolGeneralConvert(x, no_remove_warning = "XKX") } #' @rdname readUN_PopDiv #' @order 1 downloadUN_PopDiv <- function() { # nolint - url <- "https://population.un.org/wpp/Download/Files/1_Indicators%20(Standard)/EXCEL_FILES/2_Population/WPP2022_POP_F01_1_POPULATION_SINGLE_AGE_BOTH_SEXES.xlsx" + url <- "https://population.un.org/wpp/Download/Files/1_Indicators%20(Standard)/EXCEL_FILES/2_Population/WPP2022_POP_F01_1_POPULATION_SINGLE_AGE_BOTH_SEXES.xlsx" # nolint utils::download.file(url, basename(url), quiet = TRUE) # Compose meta data diff --git a/R/toolExtend2150.R b/R/toolExtend2150.R index f48ef1d..41478b2 100644 --- a/R/toolExtend2150.R +++ b/R/toolExtend2150.R @@ -36,10 +36,10 @@ bezierExtension <- function(data, timeExtend) { # If Bezier extension would lead to negative GDP, set bezier coordinates equal to start point # (comes down to a constant extension instead) - for (i in 1:nr) for (j in 1:nd) if (bc[i, 2100, j] == 0 || bc[i, 2150, j] < 0 ) bc[i, , j] <- bc[i, 2100, j] + for (i in 1:nr) for (j in 1:nd) if (bc[i, 2100, j] == 0 || bc[i, 2150, j] < 0) bc[i, , j] <- bc[i, 2100, j] x <- rep(c(2100, 2110, 2140, 2150), nr * nd) - y <- purrr::reduce(purrr::map(1:nd, ~purrr::reduce(purrr::map(1:nr, function(y) bc[y, ,.x]), c)), c) + y <- purrr::reduce(purrr::map(1:nd, ~purrr::reduce(purrr::map(1:nr, function(y) bc[y, , .x]), c)), c) z <- purrr::reduce(purrr::map(1:(nr * nd), ~rep(.x, 4)), c) # grid::bezierGrob returns the point in a weird graphical unit, and "only" returns 48 points, but is super fast. @@ -47,7 +47,7 @@ bezierExtension <- function(data, timeExtend) { cfx <- x[1] / as.numeric(bezierPoints[[1]]$x[[1]]) cfy <- y[1] / as.numeric(bezierPoints[[1]]$y[[1]]) id <- paste(purrr::reduce(purrr::map(getNames(data), ~rep(.x, nr)), c), - rep(getRegions(data), nd), + rep(getItems(data, 1), nd), sep = "-") extension <- purrr::map2(bezierPoints, id, diff --git a/R/toolGetEUcountries.R b/R/toolGetEUcountries.R index b3c800d..27afc84 100644 --- a/R/toolGetEUcountries.R +++ b/R/toolGetEUcountries.R @@ -7,7 +7,7 @@ toolGetEUcountries <- function(onlyWithARIADNEgdpData = FALSE) { dplyr::pull(.data$CountryCode) if (onlyWithARIADNEgdpData) { - x <- x[x %in% where(readSource("ARIADNE", "gdp_corona") != 0)$true$regions] + x <- x[x %in% where(readSource("ARIADNE", "gdp_corona") != 0)$true$regions] } x } diff --git a/R/toolReduce.R b/R/toolReduce.R index 95ed9bc..0beb8e7 100644 --- a/R/toolReduce.R +++ b/R/toolReduce.R @@ -2,17 +2,19 @@ toolReduce <- function(x, mbindOrFillWith = "mbind") { # Combine list elements using mbind and glue. if (mbindOrFillWith == "mbind") { x %>% - purrr::reduce(~ list(x = mbind(.x$x, .y$x), - weight = mbind(.x$weight, .y$weight), - unit = glue("{.x$unit} || {.y$unit}"), - description = glue("{.x$description} || {.y$description}"))) + purrr::reduce(~ list(x = mbind(.x$x, .y$x), + weight = mbind(.x$weight, .y$weight), + unit = glue("{.x$unit} || {.y$unit}"), + description = glue("{.x$description} || {.y$description}"))) } else if (mbindOrFillWith == "fillWith") { if (length(x) > 1) { sep <- if (length(x) == 2) " (completed with" else c(" (completed with", c(rep(",", length(x) - 3), " and")) closer <- c(rep("", length(sep) - 1), ")") helper <- purrr::map2(sep, closer, c) - } else helper <- NULL + } else { + helper <- NULL + } purrr::reduce2(x, helper, ~ list(x = toolFillWith(.x$x, .y$x), diff --git a/README.md b/README.md index 017eeaf..4831933 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Create GDP and Population Scenarios -R package **mrdrivers**, version **1.4.0** +R package **mrdrivers**, version **1.5.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) @@ -103,7 +103,7 @@ In case of questions / problems please contact Johannes Koch . +Koch J, Soergel B, Leip D, Benke F, Dietrich J (2023). _mrdrivers: Create GDP and Population Scenarios_. R package version 1.5.0, . A BibTeX entry for LaTeX users is @@ -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.4.0}, + note = {R package version 1.5.0}, url = {https://pik-piam.github.io/mrdrivers}, url = {https://github.com/pik-piam/mrdrivers}, }