From 476f3f24734f32dee64e857edff93e95ec180bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20F=C3=BChrlich?= Date: Mon, 3 Jul 2023 11:11:12 +0200 Subject: [PATCH] move rworldmap&luplot to suggests --- .buildlibrary | 2 +- CITATION.cff | 4 ++-- DESCRIPTION | 8 ++++---- NAMESPACE | 4 ---- R/validation.R | 23 +++++++++++++---------- README.md | 6 +++--- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 46c1c039..207f772d 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '232213360' +ValidationKey: '232244785' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index 27d07fb4..97adacd5 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: 'magpie4: MAgPIE outputs R package for MAgPIE version 4.x' -version: 1.188.4 -date-released: '2023-07-02' +version: 1.188.5 +date-released: '2023-07-03' abstract: Common output routines for extracting results from the MAgPIE framework (versions 4.x). authors: diff --git a/DESCRIPTION b/DESCRIPTION index d030036a..c4d1c454 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: magpie4 Title: MAgPIE outputs R package for MAgPIE version 4.x -Version: 1.188.4 -Date: 2023-07-02 +Version: 1.188.5 +Date: 2023-07-03 Authors@R: c( person("Benjamin Leon", "Bodirsky", , "bodirsky@pik-potsdam.de", role = c("aut", "cre")), person("Florian", "Humpenoeder", , "humpenoeder@pik-potsdam.de", role = "aut"), @@ -38,7 +38,6 @@ Depends: Imports: dplyr, gms, - luplot, luscale, lusweave, madrat, @@ -49,12 +48,13 @@ Imports: nonparaeff, reshape2, rlang, - rworldmap, spam, utils, stringr Suggests: covr, + luplot, + rworldmap, terra, testthat Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index 3eee27ff..d52c0848 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -280,8 +280,6 @@ importFrom(gdx,expand.set) importFrom(gdx,out) importFrom(gdx,readGDX) importFrom(gms,tardir) -importFrom(luplot,magpie2ggplot2) -importFrom(luplot,plotregionscluster) importFrom(luscale,read.spam) importFrom(luscale,speed_aggregate) importFrom(luscale,superAggregate) @@ -349,8 +347,6 @@ importFrom(mstools,toolHoldConstant) importFrom(nonparaeff,faremalm2) importFrom(reshape2,melt) importFrom(rlang,.data) -importFrom(rworldmap,joinCountryData2Map) -importFrom(rworldmap,mapCountryData) importFrom(spam,triplet) importFrom(stats,reshape) importFrom(stats,weighted.mean) diff --git a/R/validation.R b/R/validation.R index 2db8e989..cb94df26 100644 --- a/R/validation.R +++ b/R/validation.R @@ -25,12 +25,10 @@ #' @importFrom mip validationpdf #' @importFrom lusweave swopen swlatex swclose swR swtable swfigure #' @importFrom magclass getYears getRegions -#' @importFrom rworldmap joinCountryData2Map mapCountryData #' @importFrom utils methods #' @importFrom mip plotstyle #' @importFrom utils capture.output #' @importFrom magclass write.report2 -#' @importFrom luplot magpie2ggplot2 plotregionscluster validation <- function(gdx,hist,file="validation.pdf",runinfo=NULL, clusterinfo=NULL, debug=FALSE, reportfile=NULL, scenario=NULL, getReport=NULL, ...) { @@ -72,11 +70,15 @@ validation <- function(gdx,hist,file="validation.pdf",runinfo=NULL, clusterinfo= swlatex(sw,"\\subsection{World regions}") if(!is.null(clusterinfo)) { - if(is.character(clusterinfo) && length(clusterinfo)==1) clusterinfo <- readRDS(clusterinfo)$cluster - swfigure(sw,plotregionscluster, clusterinfo, fig.orientation="landscape") + rlang::check_installed("luplot") + if(is.character(clusterinfo) && length(clusterinfo)==1) { + clusterinfo <- readRDS(clusterinfo)$cluster + } + swfigure(sw,luplot::plotregionscluster, clusterinfo, fig.orientation="landscape") } else { i2iso <- readGDX(gdx,"i_to_iso", react="silent") if(!is.null(i2iso)) { + rlang::check_installed("rworldmap") map <- as.magpie(i2iso[2:1],spatial=1) col <- plotstyle(levels(as.factor(i2iso[[1]]))) plotcountrymap<-function(x,hatching=FALSE,...) { @@ -97,14 +99,14 @@ validation <- function(gdx,hist,file="validation.pdf",runinfo=NULL, clusterinfo= DF <- data.frame(country = countries,namedim = values,hatching=as.vector(x[,year,2])) dimnames(DF)[[2]][[2]] <- paste(namedim[1],substr(year,2,5)) dimnames(DF)[[2]][[3]] <- paste(namedim[2],substr(year,2,5)) - mapobject <- joinCountryData2Map(DF, joinCode = "ISO3",nameJoinColumn = "country") - mapCountryData(mapobject, nameColumnToPlot = dimnames(DF)[[2]][[2]],nameColumnToHatch=dimnames(DF)[[2]][[3]],...) + mapobject <- rworldmap::joinCountryData2Map(DF, joinCode = "ISO3",nameJoinColumn = "country") + rworldmap::mapCountryData(mapobject, nameColumnToPlot = dimnames(DF)[[2]][[2]],nameColumnToHatch=dimnames(DF)[[2]][[3]],...) } else{ DF <- data.frame(country = countries,namedim = values) dimnames(DF)[[2]][[2]] <- paste(namedim,substr(year,2,5)) - mapobject <- joinCountryData2Map(DF, joinCode = "ISO3",nameJoinColumn = "country") - mapCountryData(mapobject, nameColumnToPlot = dimnames(DF)[[2]][[2]],...) + mapobject <- rworldmap::joinCountryData2Map(DF, joinCode = "ISO3",nameJoinColumn = "country") + rworldmap::mapCountryData(mapobject, nameColumnToPlot = dimnames(DF)[[2]][[2]],...) } @@ -140,16 +142,17 @@ validation <- function(gdx,hist,file="validation.pdf",runinfo=NULL, clusterinfo= swlatex(sw,"\\subsection{Goal function value}") costs <- costs(gdx,level = "glo", sum=FALSE) if(!is.null(costs)) { + rlang::check_installed("luplot") costs_tot <- dimSums(costs, dim=3) swtable(sw,costs_tot/1000,table.placement="H",caption.placement="top",transpose=TRUE,caption="Global costs (billion USD)",vert.lines=1,align="c") # decomposition of costs (in billion USD and in ratios) swlatex(sw,"\\subsubsection{Total costs decomposition}") - swfigure(sw, magpie2ggplot2, costs/1000, geom="bar", group="Data1", color="Data1", + swfigure(sw, luplot::magpie2ggplot2, costs/1000, geom="bar", group="Data1", color="Data1", ylab="Total costs decompositino [bill. US$]", stack=TRUE, fill="Data1", stack_share=F, facet_x="Region", legend_position="bottom", legend_ncol=2) - swfigure(sw, magpie2ggplot2, costs, geom="bar", group="Data1", color="Data1", + swfigure(sw, luplot::magpie2ggplot2, costs, geom="bar", group="Data1", color="Data1", ylab="Total costs decompositon [%]", stack=TRUE, fill="Data1", stack_share=T, facet_x="Region", legend_position="bottom", legend_ncol=2) } else { diff --git a/README.md b/README.md index 096432e4..0d5a80ea 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MAgPIE outputs R package for MAgPIE version 4.x -R package **magpie4**, version **1.188.4** +R package **magpie4**, version **1.188.5** [![CRAN status](https://www.r-pkg.org/badges/version/magpie4)](https://cran.r-project.org/package=magpie4) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1158582.svg)](https://doi.org/10.5281/zenodo.1158582) [![R build status](https://github.com/pik-piam/magpie4/workflows/check/badge.svg)](https://github.com/pik-piam/magpie4/actions) [![codecov](https://codecov.io/gh/pik-piam/magpie4/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/magpie4) [![r-universe](https://pik-piam.r-universe.dev/badges/magpie4)](https://pik-piam.r-universe.dev/builds) @@ -39,7 +39,7 @@ In case of questions / problems please contact Benjamin Leon Bodirsky , R package version 1.188.4, . +Bodirsky B, Humpenoeder F, Dietrich J, Stevanovic M, Weindl I, Karstens K, Wang X, Mishra A, Beier F, Breier J, Yalew A, Chen D, Biewald A, Wirth S, von Jeetze P, Leip D, Crawford M, Alves M (2023). _magpie4: MAgPIE outputs R package for MAgPIE version 4.x_. doi:10.5281/zenodo.1158582 , R package version 1.188.5, . A BibTeX entry for LaTeX users is @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is title = {magpie4: MAgPIE outputs R package for MAgPIE version 4.x}, author = {Benjamin Leon Bodirsky and Florian Humpenoeder and Jan Philipp Dietrich and Miodrag Stevanovic and Isabelle Weindl and Kristine Karstens and Xiaoxi Wang and Abhijeet Mishra and Felicitas Beier and Jannes Breier and Amsalu Woldie Yalew and David Chen and Anne Biewald and Stephen Wirth and Patrick {von Jeetze} and Debbora Leip and Michael Crawford and Marcos Alves}, year = {2023}, - note = {R package version 1.188.4}, + note = {R package version 1.188.5}, doi = {10.5281/zenodo.1158582}, url = {https://github.com/pik-piam/magpie4}, }