Skip to content

Commit

Permalink
Merge pull request #46 from pfuehrlich-pik/master
Browse files Browse the repository at this point in the history
move rworldmap & luplot to suggests
  • Loading branch information
pfuehrlich-pik authored Jul 3, 2023
2 parents 6dd0dab + 476f3f2 commit f5cf1b2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '232213360'
ValidationKey: '232244785'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
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: '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:
Expand Down
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre")),
person("Florian", "Humpenoeder", , "[email protected]", role = "aut"),
Expand Down Expand Up @@ -38,7 +38,6 @@ Depends:
Imports:
dplyr,
gms,
luplot,
luscale,
lusweave,
madrat,
Expand All @@ -49,12 +48,13 @@ Imports:
nonparaeff,
reshape2,
rlang,
rworldmap,
spam,
utils,
stringr
Suggests:
covr,
luplot,
rworldmap,
terra,
testthat
Encoding: UTF-8
Expand Down
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
23 changes: 13 additions & 10 deletions R/validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) {

Expand Down Expand Up @@ -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,...) {
Expand All @@ -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]],...)

}

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Benjamin Leon Bodirsky <bodirsky@

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

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 <https://doi.org/10.5281/zenodo.1158582>, R package version 1.188.4, <https://github.com/pik-piam/magpie4>.
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 <https://doi.org/10.5281/zenodo.1158582>, R package version 1.188.5, <https://github.com/pik-piam/magpie4>.

A BibTeX entry for LaTeX users is

Expand All @@ -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},
}
Expand Down

0 comments on commit f5cf1b2

Please sign in to comment.