Skip to content

Commit

Permalink
Merge pull request #10 from johanneskoch94/main
Browse files Browse the repository at this point in the history
Make scenario argument in mrdrivers functions explicit
  • Loading branch information
johanneskoch94 authored Feb 7, 2025
2 parents 39f14f7 + 47c1e94 commit d468a3a
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '1464453'
ValidationKey: '1489250'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand All @@ -7,3 +7,4 @@ AcceptedNotes: .* includes the non-default packages.*
allowLinterWarnings: no
enforceVersionUpdate: no
skipCoverage: no
AutocreateCITATION: yes
7 changes: 7 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ jobs:
[ -f requirements.txt ] && python -m pip install --upgrade pip wheel || true
[ -f requirements.txt ] && pip install -r requirements.txt || true
- name: Run pre-commit checks
shell: bash
run: |
python -m pip install pre-commit
python -m pip freeze --local
pre-commit run --show-diff-on-failure --color=always --all-files
- 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 @@ -25,4 +25,4 @@ repos:
- id: readme-rmd-rendered
- id: use-tidy-description
ci:
autoupdate_schedule: quarterly
autoupdate_schedule: weekly
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: 'mrfactors: MADRaT based package on factor inputs'
version: 0.7.3
date-released: '2024-12-04'
version: 0.7.4
date-released: '2025-02-06'
abstract: This package provides functions for MAgPIE input data on factor inputs to
agricultural production (with a focus on capital and labor).
authors:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: mrfactors
Title: MADRaT based package on factor inputs
Version: 0.7.3
Date: 2024-12-04
Version: 0.7.4
Date: 2025-02-06
Authors@R:
c(person("Debbora", "Leip", , "leip@pik-potsdam.de", role = c("aut", "cre")),
person("Edna", "Molina Bacca", role = "aut"))
Expand Down
6 changes: 5 additions & 1 deletion R/calcAgCapLabourShare.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ calcAgCapLabourShare <- function(fillWithRegression = TRUE, projection = FALSE)
regCoeff <- calcOutput("RegFactorShare", aggregate = FALSE)

# calculate GDPpc [USD2017PPP] for regression
gdp <- calcOutput("GDPpc", naming = "scenario", unit = "constant 2017 Int$PPP", aggregate = FALSE)
gdp <- calcOutput("GDPpc",
scenario = "SSPs",
naming = "scenario",
unit = "constant 2017 Int$PPP",
aggregate = FALSE)
if (!isFALSE(projection)) {
years <- setdiff(getItems(gdp, dim = 2), paste0("y", seq(2105, 2150, 5)))
gdp <- gdp[, years, projection]
Expand Down
4 changes: 2 additions & 2 deletions R/calcHourlyLaborCosts.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ calcHourlyLaborCosts <- function(datasource = "USDA_FAO", dataVersionILO = "Aug2
# remove outliers
hourlyCosts[hourlyCosts > 100] <- 0 # unreasonable high values
gdpMERpc <- calcOutput("GDPpc",
scenario = "SSPs",
scenario = "SSP2",
unit = "constant 2017 US$MER",
average2020 = FALSE,
naming = "scenario",
aggregate = FALSE)[getItems(hourlyCosts, dim = 1), getItems(hourlyCosts, dim = 2), "SSP2"]
aggregate = FALSE)[getItems(hourlyCosts, dim = 1), getItems(hourlyCosts, dim = 2), ]
hourlyCosts[hourlyCosts < 0.1 & gdpMERpc > 3000] <- 0 # unreasonable low values

} else if (datasource == "USDA_FAO") { # from USDA/FAO labor costs for crop+livst, ag. empl. and weekly hours
Expand Down
4 changes: 2 additions & 2 deletions R/calcRegFactorShare.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ calcRegFactorShare <- function(datasource = "USDA", caseStudies = "CountryCaseSt
extrapolation_type = "constant", integrate_interpolated_years = TRUE)

# dependent variable
gdp <- calcOutput("GDPpc", naming = "scenario", unit = "constant 2017 Int$PPP", aggregate = FALSE)[, , "SSP2"]
gdp <- calcOutput("GDPpc", scenario = "SSP2", unit = "constant 2017 Int$PPP", aggregate = FALSE)
gdp <- setNames(gdp, "GDP_pc")

# mapping to case studies
Expand All @@ -55,7 +55,7 @@ calcRegFactorShare <- function(datasource = "USDA", caseStudies = "CountryCaseSt
from = "ISO", to = caseStudies, dim = 1)

# aggregate GDP per capita using population as weight
pop <- calcOutput("Population", naming = "scenario", aggregate = FALSE)[, , "SSP2"]
pop <- calcOutput("Population", scenario = "SSP2", naming = "scenario", aggregate = FALSE)
weight2 <- pop[countries, getYears(capShare), ]
weight2[weight == 1e-12] <- 1e-12
gdp <- toolAggregate(gdp[countries, getYears(capShare), ], rel = mapping,
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MADRaT based package on factor inputs

R package **mrfactors**, version **0.7.3**
R package **mrfactors**, version **0.7.4**

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

Expand Down Expand Up @@ -38,16 +38,17 @@ In case of questions / problems please contact Debbora Leip <leip@pik-potsdam.de

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

Leip D, Molina Bacca E (2024). _mrfactors: MADRaT based package on factor inputs_. R package version 0.7.3, <URL: https://github.com/pik-piam/mrfactors>.
Leip D, Molina Bacca E (2025). "mrfactors: MADRaT based package on factor inputs." Version: 0.7.4, <https://github.com/pik-piam/mrfactors>.

A BibTeX entry for LaTeX users is

```latex
@Manual{,
@Misc{,
title = {mrfactors: MADRaT based package on factor inputs},
author = {Debbora Leip and Edna {Molina Bacca}},
year = {2024},
note = {R package version 0.7.3},
date = {2025-02-06},
year = {2025},
url = {https://github.com/pik-piam/mrfactors},
note = {Version: 0.7.4},
}
```

0 comments on commit d468a3a

Please sign in to comment.