Skip to content

Commit

Permalink
fix currency conversion in FAO VOP
Browse files Browse the repository at this point in the history
  • Loading branch information
caviddhen committed Mar 5, 2024
1 parent e052c3c commit ef89cc5
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '27494200'
ValidationKey: '27523717'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
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: 'mrcommons: MadRat commons Input Data Library'
version: 1.39.0
date-released: '2024-02-27'
version: 1.39.1
date-released: '2024-03-05'
abstract: Provides useful functions and a common structure to all the input data required
to run models like MAgPIE and REMIND of model input data.
authors:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: mrcommons
Type: Package
Title: MadRat commons Input Data Library
Version: 1.39.0
Date: 2024-02-27
Version: 1.39.1
Date: 2024-03-05
Authors@R: c(person("Benjamin Leon", "Bodirsky", email = "bodirsky@pik-potsdam.de", role = "aut"),
person("Kristine", "Karstens", role = "aut"),
person("Lavinia", "Baumstark", role = "aut"),
Expand Down
2 changes: 1 addition & 1 deletion R/calcAgProductionValue.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ calcAgProductionValue <- function(datasource = "FAO") {

if (datasource == "FAO") {
data <- readSource("FAO_online", "ValueOfProd")
data <- data[, , "Gross_Production_Value_(constant_2014_2016_million_US$)_(USD)"]
data <- data[, , "Gross_Production_Value_(USDMER05)_(1000_US$)"]
data <- collapseNames(data)

aggregation <- toolGetMapping("FAOitems.csv", type = "sectoral", where = "mappingfolder")
Expand Down
14 changes: 8 additions & 6 deletions R/convertFAO_online.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @param x MAgPIE object containing original values
#' @param subtype The FAO file type, e.g.: CBCrop
#' @return Data as MAgPIE object with common country list
#' @author Ulrich Kreidenweis, Abhijeet Mishra, Mishko Stevanovic, David Klein, Edna Molina Bacca
#' @author Ulrich Kreidenweis, Abhijeet Mishra, Mishko Stevanovic, David Klein, Daivd Chen, Edna Molina Bacca
#' @seealso [readFAO()], [readSource()],
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -120,17 +120,17 @@ convertFAO_online <- function(x, subtype) { # nolint: cyclocomp_linter, object_n
## data for Eritrea ERI and South Sudan SSD added with 0 if not existing after the split
## to make toolISOhistorical work
if (any(getItems(x, dim = 1.1) == "XET") &&
any(getItems(x, dim = 1.1) == "ETH") &&
!any(getItems(x, dim = 1.1) == "ERI")) {
any(getItems(x, dim = 1.1) == "ETH") &&
!any(getItems(x, dim = 1.1) == "ERI")) {
xERI <- x["ETH", , ]
xERI[, , ] <- 0
getItems(xERI, dim = 1) <- "ERI"
x <- magpiesort(mbind(x, xERI))
}

if (any(getItems(x, dim = 1.1) == "XSD") &&
any(getItems(x, dim = 1.1) == "SDN") &&
!any(getItems(x, dim = 1.1) == "SSD")) {
any(getItems(x, dim = 1.1) == "SDN") &&
!any(getItems(x, dim = 1.1) == "SSD")) {
xSSD <- x["SDN", , ]
xSSD[, , ] <- 0
getItems(xSSD, dim = 1) <- "SSD"
Expand Down Expand Up @@ -322,7 +322,7 @@ convertFAO_online <- function(x, subtype) { # nolint: cyclocomp_linter, object_n
countries <- unique(rownames(which(!is.na(x[, , itemn, pmatch = TRUE]), arr.ind = TRUE)))
countries <- setdiff(getItems(x, dim = 1.1), countries)
x[countries, , itemn, pmatch = TRUE] <- x[countries, , litemn, pmatch = TRUE] /
mapping$Price_factor[grep(item, mapping$FAO_carcass)]
mapping$Price_factor[grep(item, mapping$FAO_carcass)]
}
x[is.na(x)] <- 0
x <- toolISOhistorical(x, overwrite = TRUE, additional_mapping = additionalMapping)
Expand All @@ -340,9 +340,11 @@ convertFAO_online <- function(x, subtype) { # nolint: cyclocomp_linter, object_n
}

} else if (subtype == "ValueOfProd") {
x <- x[, , "Gross_Production_Value_(current_thousand_US$)_(1000_US$)"]
x <- convertGDP(x, unit_in = "current US$MER",
unit_out = "constant 2005 US$MER",
replace_NAs = "no_conversion")
getNames(x, dim = 2) <- "Gross_Production_Value_(USDMER05)_(1000_US$)"
} else {
cat("Specify in convertFAO whether dataset contains absolute or relative values!")
}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MadRat commons Input Data Library

R package **mrcommons**, version **1.39.0**
R package **mrcommons**, version **1.39.1**

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

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Jan Philipp Dietrich <dietrich@pi

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

Bodirsky B, Karstens K, Baumstark L, Weindl I, Wang X, Mishra A, Wirth S, Stevanovic M, Steinmetz N, Kreidenweis U, Rodrigues R, Popov R, Humpenoeder F, Giannousakis A, Levesque A, Klein D, Araujo E, Beier F, Oeser J, Pehl M, Leip D, Crawford M, Molina Bacca E, von Jeetze P, Martinelli E, Schreyer F, Soergel B, Sauer P, Hötten D, Hasse R, Abrahão G, Weigmann P, Dietrich J (2024). _mrcommons: MadRat commons Input Data Library_. doi:10.5281/zenodo.3822009 <https://doi.org/10.5281/zenodo.3822009>, R package version 1.39.0, <https://github.com/pik-piam/mrcommons>.
Bodirsky B, Karstens K, Baumstark L, Weindl I, Wang X, Mishra A, Wirth S, Stevanovic M, Steinmetz N, Kreidenweis U, Rodrigues R, Popov R, Humpenoeder F, Giannousakis A, Levesque A, Klein D, Araujo E, Beier F, Oeser J, Pehl M, Leip D, Crawford M, Molina Bacca E, von Jeetze P, Martinelli E, Schreyer F, Soergel B, Sauer P, Hötten D, Hasse R, Abrahão G, Weigmann P, Dietrich J (2024). _mrcommons: MadRat commons Input Data Library_. doi: 10.5281/zenodo.3822009 (URL: https://doi.org/10.5281/zenodo.3822009), R package version 1.39.1, <URL: https://github.com/pik-piam/mrcommons>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is
title = {mrcommons: MadRat commons Input Data Library},
author = {Benjamin Leon Bodirsky and Kristine Karstens and Lavinia Baumstark and Isabelle Weindl and Xiaoxi Wang and Abhijeet Mishra and Stephen Wirth and Mishko Stevanovic and Nele Steinmetz and Ulrich Kreidenweis and Renato Rodrigues and Roman Popov and Florian Humpenoeder and Anastasis Giannousakis and Antoine Levesque and David Klein and Ewerton Araujo and Felicitas Beier and Julian Oeser and Michaja Pehl and Debbora Leip and Michael Crawford and Edna {Molina Bacca} and Patrick {von Jeetze} and Eleonora Martinelli and Felix Schreyer and Bjoern Soergel and Pascal Sauer and David Hötten and Robin Hasse and Gabriel Abrahão and Pascal Weigmann and Jan Philipp Dietrich},
year = {2024},
note = {R package version 1.39.0},
note = {R package version 1.39.1},
doi = {10.5281/zenodo.3822009},
url = {https://github.com/pik-piam/mrcommons},
}
Expand Down
2 changes: 1 addition & 1 deletion man/convertFAO_online.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ef89cc5

Please sign in to comment.