diff --git a/.buildlibrary b/.buildlibrary index 0fe3297..79fe5d3 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,8 +1,8 @@ -ValidationKey: '218185' +ValidationKey: '397020' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' -AcceptedNotes: ~ +AcceptedNotes: Namespaces in Imports field not imported from\:\n *.mip. .piamPlotComparison. allowLinterWarnings: no enforceVersionUpdate: no diff --git a/.gitignore b/.gitignore index 5b6a065..b7fdc09 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ .Rhistory .RData .Ruserdata +*.pdf +*_Rmd/* \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 243f46a..62f13da 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ exclude: '^tests/testthat/_snaps/.*$' repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # frozen: v4.6.0 hooks: - id: check-case-conflict - id: check-json @@ -15,7 +15,7 @@ repos: - id: mixed-line-ending - repo: https://github.com/lorenzwalthert/precommit - rev: v0.4.0 + rev: 7910e0323d7213f34275a7a562b9ef0fde8ce1b9 # frozen: v0.4.2 hooks: - id: parsable-R - id: deps-in-desc diff --git a/CITATION.cff b/CITATION.cff index 406bf24..28a7978 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: 'reportbrick: Reporting package for BRICK' -version: 0.1.1 -date-released: '2024-04-22' +version: 0.2.0 +date-released: '2024-05-08' abstract: This package contains BRICK-specific routines to report model results. The main functionality is to generate a mif-file from a given BRICK model run folder. authors: diff --git a/DESCRIPTION b/DESCRIPTION index ab0b9fc..f1b5042 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: reportbrick Title: Reporting package for BRICK -Version: 0.1.1 -Date: 2024-04-22 +Version: 0.2.0 +Date: 2024-05-08 Authors@R: person("Robin", "Hasse", , "robin.hasse@pik-potsdam.de", role = c("aut", "cre"), @@ -15,6 +15,8 @@ Imports: gamstransfer (>= 3.0.1), madrat, magclass, + mip (>= 0.148.15), + piamPlotComparison, yaml Suggests: covr, diff --git a/README.md b/README.md index af8aebf..67953d0 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Reporting package for BRICK -R package **reportbrick**, version **0.1.1** +R package **reportbrick**, version **0.2.0** -[![CRAN status](https://www.r-pkg.org/badges/version/reportbrick)](https://cran.r-project.org/package=reportbrick) [![R build status](https://github.com/pik-piam/reportbrick/workflows/check/badge.svg)](https://github.com/pik-piam/reportbrick/actions) [![codecov](https://codecov.io/gh/pik-piam/reportbrick/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/reportbrick) +[![CRAN status](https://www.r-pkg.org/badges/version/reportbrick)](https://cran.r-project.org/package=reportbrick) [![R build status](https://github.com/pik-piam/reportbrick/workflows/check/badge.svg)](https://github.com/pik-piam/reportbrick/actions) [![codecov](https://codecov.io/gh/pik-piam/reportbrick/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/reportbrick) [![r-universe](https://pik-piam.r-universe.dev/badges/reportbrick)](https://pik-piam.r-universe.dev/builds) ## Purpose and Functionality @@ -38,7 +38,7 @@ In case of questions / problems please contact Robin Hasse . +Hasse R (2024). _reportbrick: Reporting package for BRICK_. R package version 0.2.0, . A BibTeX entry for LaTeX users is @@ -47,7 +47,7 @@ A BibTeX entry for LaTeX users is title = {reportbrick: Reporting package for BRICK}, author = {Robin Hasse}, year = {2024}, - note = {R package version 0.1.1}, + note = {R package version 0.2.0}, url = {https://github.com/pik-piam/reportbrick}, } ``` diff --git a/inst/compareScenarios/cs_01_stocks_flows.Rmd b/inst/compareScenarios/cs_01_stocks_flows.Rmd new file mode 100644 index 0000000..57b63ee --- /dev/null +++ b/inst/compareScenarios/cs_01_stocks_flows.Rmd @@ -0,0 +1,49 @@ +# Stock and flows + +## Building stock + +```{r stock vars} +tot <- "Stock|Buildings" +subsec <- c("Stock|Residential", + "Stock|Commercial") +``` + +```{r StockSubsector} +showAreaAndBarPlots(data, vars = subsec, tot = tot, orderVars = "user", scales = "fixed") +``` + +### All buildings + +### Residential +```{r residential stock vars} +tot <- "Stock|Residential" +heatingRes <- paste(tot, heating, sep = "|") +vintageRes <- paste(tot, vintage, sep = "|") +typeRes <- paste(tot, type, sep = "|") +locationRes <- paste(tot, location, sep = "|") +``` + +#### by building type +```{r Stock-Residential-(type)} +showAreaAndBarPlots(data, vars = typeRes, tot = tot, orderVars = "user", scales = "fixed") +walk(typeRes, showLinePlots, data = data) +``` + +#### by location +```{r Stock-Residential-(location)} +showAreaAndBarPlots(data, vars = locationRes, tot = tot, orderVars = "user", scales = "fixed") +walk(locationRes, showLinePlots, data = data) +``` + +#### by construction cohort +```{r Stock-Residential-(vintage)} +showAreaAndBarPlots(data, vars = rev(vintageRes), tot = tot, orderVars = "user", scales = "fixed") +``` + +#### by Space heating +```{r Stock-Residential-(heating)} +showAreaAndBarPlots(data, vars = heatingRes, tot = tot, orderVars = "user", scales = "fixed") +walk(heatingRes, showLinePlots, data = data) +``` + +### Commercial diff --git a/inst/compareScenarios/preprocessing.R b/inst/compareScenarios/preprocessing.R new file mode 100644 index 0000000..b385de9 --- /dev/null +++ b/inst/compareScenarios/preprocessing.R @@ -0,0 +1,41 @@ +# Load additional libraries ---------------------------------------------------- + +library(dplyr) # nolint: undesirable_function_linter. + + + +# BRICK sets ------------------------------------------------------------------- + +# Sets are used in Rmd files to select variables + +subsec <- c( + "Residential", + "Commercial" +) +type <- c( + "SFH", + "MFH" +) +location <- c( + "Urban", + "Rural" +) +heating <- c( + "Biomass", + "District heating", + "Heat pump", + "Resistive electric", + "Gas", + "Liquids", + "Coal" +) + +# automatic identification of vintages to allow for different model resolutions +vintageRegex <- "(Before|After) \\d{4}|\\d{4} - \\d{4}" +vintage <- grep(vintageRegex, unique(data[["variable"]]), value = TRUE) %>% + unique() %>% + sub(pattern = paste0("^.*(", vintageRegex, ").*$"), replacement = "\\1") %>% + unique() +vintage <- c(grep("^Before", vintage, value = TRUE), + sort(grep("^\\d{4}", vintage, value = TRUE)), + grep("^After", vintage, value = TRUE)) diff --git a/man/dot-agg.Rd b/man/dot-agg.Rd index 7a0b0de..a813028 100644 --- a/man/dot-agg.Rd +++ b/man/dot-agg.Rd @@ -4,12 +4,14 @@ \alias{.agg} \title{Aggregate} \usage{ -.agg(x, agg) +.agg(x, agg, silent = TRUE) } \arguments{ \item{x}{MagPIE object, BRICK object} \item{agg}{named vector of dimensions to aggregate.} + +\item{silent}{boolean, suppress warnings and printing of dimension mapping} } \value{ aggregated MagPIE objects without sub dimensions in dim 3 diff --git a/man/dot-readBrickSets.Rd b/man/readBrickSets.Rd similarity index 68% rename from man/dot-readBrickSets.Rd rename to man/readBrickSets.Rd index dc4cb89..e2ed1ad 100644 --- a/man/dot-readBrickSets.Rd +++ b/man/readBrickSets.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/reportAgg.R -\name{.readBrickSets} -\alias{.readBrickSets} +% Please edit documentation in R/readBrickSets.R +\name{readBrickSets} +\alias{readBrickSets} \title{Read brickSets mapping} \usage{ -.readBrickSets(tmpl) +readBrickSets(tmpl) } \arguments{ \item{tmpl}{character, BRICK reporting template} diff --git a/man/reportAgg.Rd b/man/reportAgg.Rd index ab6e2e2..bb3f417 100644 --- a/man/reportAgg.Rd +++ b/man/reportAgg.Rd @@ -4,7 +4,14 @@ \alias{reportAgg} \title{Report aggregated quantities} \usage{ -reportAgg(x, name, tmpl = NULL, agg = NULL, rprt = NULL, silent = TRUE) +reportAgg( + x, + name, + brickSets = readBrickSets(NULL), + agg = NULL, + rprt = NULL, + silent = TRUE +) } \arguments{ \item{x}{MagPIE object, BRICK object} @@ -12,7 +19,7 @@ reportAgg(x, name, tmpl = NULL, agg = NULL, rprt = NULL, silent = TRUE) \item{name}{character, name of reporting variable. reported dimensions passed with \code{rprt} have to be escaped with curly brackets.} -\item{tmpl}{character, BRICK reporting template} +\item{brickSets}{named list, BRICK reporting template} \item{agg}{named vector of dimensions to aggregate. Names are dimension names of \code{x} and values are either set elements or subsets of set elements diff --git a/man/reportBuildingStock.Rd b/man/reportBuildingStock.Rd index 6f76e3c..369f685 100644 --- a/man/reportBuildingStock.Rd +++ b/man/reportBuildingStock.Rd @@ -4,12 +4,12 @@ \alias{reportBuildingStock} \title{Report building Stock} \usage{ -reportBuildingStock(gdx, tmpl = NULL) +reportBuildingStock(gdx, brickSets = NULL) } \arguments{ \item{gdx}{gams transfer container of the BRICK GDX} -\item{tmpl}{character, BRICK reporting template} +\item{brickSets}{character, BRICK reporting template} } \description{ Report quantities describing the stock of buildings diff --git a/man/reportConstruction.Rd b/man/reportConstruction.Rd index 1fd880c..121ab48 100644 --- a/man/reportConstruction.Rd +++ b/man/reportConstruction.Rd @@ -4,12 +4,12 @@ \alias{reportConstruction} \title{Report construction} \usage{ -reportConstruction(gdx, tmpl = NULL) +reportConstruction(gdx, brickSets = NULL) } \arguments{ \item{gdx}{gams transfer container of the BRICK GDX} -\item{tmpl}{character, BRICK reporting template} +\item{brickSets}{character, BRICK reporting template} } \description{ Report quantities describing the construction of new buildings diff --git a/man/reportDemolition.Rd b/man/reportDemolition.Rd index 4df61c4..4ee81af 100644 --- a/man/reportDemolition.Rd +++ b/man/reportDemolition.Rd @@ -4,12 +4,12 @@ \alias{reportDemolition} \title{Report demolition} \usage{ -reportDemolition(gdx, tmpl = NULL) +reportDemolition(gdx, brickSets = NULL) } \arguments{ \item{gdx}{gams transfer container of the BRICK GDX} -\item{tmpl}{character, BRICK reporting template} +\item{brickSets}{character, BRICK reporting template} } \description{ Report quantities describing the demolition of buildings