From 1358efe485639dda3b39ce36695347cbcc7b3953 Mon Sep 17 00:00:00 2001 From: Felicitas Date: Mon, 8 Jan 2024 11:01:49 +0100 Subject: [PATCH] Changed min to 0 and max to very high value in EATLancet recommendation to simplify GAMS code. And linter fixes. --- .buildlibrary | 2 +- CITATION.cff | 4 +-- DESCRIPTION | 4 +-- R/calcNutritionAttributes.R | 8 ++--- R/convertEATLancet.R | 64 ++++++++++++++++--------------------- README.md | 8 ++--- man/convertEATLancet.Rd | 11 +++---- 7 files changed, 46 insertions(+), 55 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index d1e2ed04..ded5e9ef 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '10308853' +ValidationKey: '10338520' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/CITATION.cff b/CITATION.cff index 3976de55..40f60aad 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: 'mrland: MadRaT land data package' -version: 0.52.3 -date-released: '2023-12-20' +version: 0.52.4 +date-released: '2024-01-08' abstract: The package provides land related data via the madrat framework. authors: - family-names: Dietrich diff --git a/DESCRIPTION b/DESCRIPTION index 3f2d2181..6f559038 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mrland Title: MadRaT land data package -Version: 0.52.3 -Date: 2023-12-20 +Version: 0.52.4 +Date: 2024-01-08 Authors@R: c( person("Jan Philipp", "Dietrich", , "dietrich@pik-potsdam.de", role = c("aut", "cre")), person("Abhijeet", "Mishra", role = "aut"), diff --git a/R/calcNutritionAttributes.R b/R/calcNutritionAttributes.R index c87a1411..5544ce02 100644 --- a/R/calcNutritionAttributes.R +++ b/R/calcNutritionAttributes.R @@ -26,10 +26,10 @@ calcNutritionAttributes <- function() { fooduseFlour <- dimSums(massbalance[, , c("food", "flour1")][, , c("ge", "nr")], dim = c(1, 3.2), na.rm = TRUE) if (any(household > fooduseFlour)) { - message(paste("The following items violate massbalance constraints:", - paste(unique(dimnames(household)[[3]][which(household > fooduseFlour, arr.ind = TRUE)[, 3]]), - collapse = " "), - ". Violating items are corrected through household balance flow.")) + message(paste("The following items violate massbalance constraints: ", + paste(unique(dimnames(household)[[3]][which(household > fooduseFlour, arr.ind = TRUE)[, 3]]), + collapse = " "), + ". Violating items are corrected through household balance flow.")) household[household > fooduseFlour] <- fooduseFlour[household > fooduseFlour] } diff --git a/R/convertEATLancet.R b/R/convertEATLancet.R index 35648a07..42ff71aa 100644 --- a/R/convertEATLancet.R +++ b/R/convertEATLancet.R @@ -1,51 +1,43 @@ -#' Convert data from the EAT Lancet Comission -#' -#' Convert data from the EAT Lancet Comission to ISO country level. -#' -#' +#' @title convertEATLancet +#' @description Convert data from the EAT Lancet Commission to be used in MAgPIE +#' #' @param x MAgPIE object containing EAT Lancet data at mixed country-region #' resolution #' @param subtype Type of EAT Lancet data that should be read. Available types are: -#' \itemize{ +#' \itemize{ #' \item \code{cons_data}: Consumption analysis ("EAT_Lancet_cons_data.csv") #' \item \code{recommend}: Food recommendations ("EAT_Lancet_recommendations.csv") #' } #' @return EAT Lancet data as MAgPIE object at ISO country level -#' @author Isabelle Weindl +#' @author Isabelle Weindl, Felicitas Beier #' @seealso \code{\link{readSource}} #' @examples -#' #' \dontrun{ -#' a <- readSource(type="EATLancet",subtype="cons_data") +#' a <- readSource(type = "EATLancet", subtype = "cons_data") #' } #' @importFrom madrat getISOlist -convertEATLancet <- function(x,subtype) { - -if(subtype == "cons_data"){ - - y <- toolAggregate(x, "regionmappingEATLancet.csv", weight=NULL ) - -} else if (subtype == "recommend") { - - iso <- getISOlist(type = "all") - mapping <- cbind(rep("GLO",length(iso)),as.character(iso)) - y <- toolAggregate(x, rel = mapping, weight=NULL ) - -} else { - - stop("Not a valid subtype!") - -} - - return(y) -} - - +convertEATLancet <- function(x, subtype) { + + if (subtype == "cons_data") { + + y <- toolAggregate(x, "regionmappingEATLancet.csv", weight = NULL) + + } else if (subtype == "recommend") { + # replace NA's for min and max values + x[, , "min"] <- ifelse(is.na(x[, , "min"]), 0, x[, , "min"]) + x[, , "max"] <- ifelse(is.na(x[, , "max"]), 999999, x[, , "max"]) - - + # expand to all iso countries + iso <- getISOlist(type = "all") + mapping <- cbind(rep("GLO", length(iso)), as.character(iso)) + y <- toolAggregate(x, rel = mapping, weight = NULL) - - - + } else { + + stop("Not a valid subtype! Please select cons_data or recommend in readEATLancet function.") + + } + + return(y) +} diff --git a/README.md b/README.md index b5b993a7..34dccbcf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MadRaT land data package -R package **mrland**, version **0.52.3** +R package **mrland**, version **0.52.4** [![CRAN status](https://www.r-pkg.org/badges/version/mrland)](https://cran.r-project.org/package=mrland) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3822083.svg)](https://doi.org/10.5281/zenodo.3822083) [![R build status](https://github.com/pik-piam/mrland/workflows/check/badge.svg)](https://github.com/pik-piam/mrland/actions) [![codecov](https://codecov.io/gh/pik-piam/mrland/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrland) [![r-universe](https://pik-piam.r-universe.dev/badges/mrland)](https://pik-piam.r-universe.dev/builds) @@ -39,7 +39,7 @@ In case of questions / problems please contact Jan Philipp Dietrich , R package version 0.52.3, . +Dietrich J, Mishra A, Weindl I, Bodirsky B, Wang X, Baumstark L, Kreidenweis U, Klein D, Steinmetz N, Chen D, Humpenoeder F, von Jeetze P, Wirth S, Beier F, Hoetten D (2024). _mrland: MadRaT land data package_. doi:10.5281/zenodo.3822083 , R package version 0.52.4, . A BibTeX entry for LaTeX users is @@ -47,8 +47,8 @@ A BibTeX entry for LaTeX users is @Manual{, title = {mrland: MadRaT land data package}, author = {Jan Philipp Dietrich and Abhijeet Mishra and Isabelle Weindl and Benjamin Leon Bodirsky and Xiaoxi Wang and Lavinia Baumstark and Ulrich Kreidenweis and David Klein and Nele Steinmetz and David Chen and Florian Humpenoeder and Patrick {von Jeetze} and Stephen Wirth and Felicitas Beier and David Hoetten}, - year = {2023}, - note = {R package version 0.52.3}, + year = {2024}, + note = {R package version 0.52.4}, doi = {10.5281/zenodo.3822083}, url = {https://github.com/pik-piam/mrland}, } diff --git a/man/convertEATLancet.Rd b/man/convertEATLancet.Rd index 9be3ac65..da497d3d 100644 --- a/man/convertEATLancet.Rd +++ b/man/convertEATLancet.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/convertEATLancet.R \name{convertEATLancet} \alias{convertEATLancet} -\title{Convert data from the EAT Lancet Comission} +\title{convertEATLancet} \usage{ convertEATLancet(x, subtype) } @@ -11,7 +11,7 @@ convertEATLancet(x, subtype) resolution} \item{subtype}{Type of EAT Lancet data that should be read. Available types are: -\itemize{ +\itemize{ \item \code{cons_data}: Consumption analysis ("EAT_Lancet_cons_data.csv") \item \code{recommend}: Food recommendations ("EAT_Lancet_recommendations.csv") }} @@ -20,17 +20,16 @@ resolution} EAT Lancet data as MAgPIE object at ISO country level } \description{ -Convert data from the EAT Lancet Comission to ISO country level. +Convert data from the EAT Lancet Commission to be used in MAgPIE } \examples{ - \dontrun{ -a <- readSource(type="EATLancet",subtype="cons_data") +a <- readSource(type = "EATLancet", subtype = "cons_data") } } \seealso{ \code{\link{readSource}} } \author{ -Isabelle Weindl +Isabelle Weindl, Felicitas Beier }