diff --git a/.buildlibrary b/.buildlibrary index fccbd38..c86c969 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '814793' +ValidationKey: '834834' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index 1835dda..07757d2 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.4.1 -date-released: '2024-05-30' +version: 0.4.2 +date-released: '2024-06-03' 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 ea3526d..a5eed34 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: reportbrick Title: Reporting package for BRICK -Version: 0.4.1 -Date: 2024-05-30 +Version: 0.4.2 +Date: 2024-06-03 Authors@R: c( person("Robin", "Hasse", , "robin.hasse@pik-potsdam.de", role = c("aut", "cre"), @@ -21,7 +21,7 @@ Imports: knitr, madrat, magclass, - mip (>= 0.148.17), + mip (>= 0.148.18), piamPlotComparison, piamutils (>= 0.0.9), purrr, diff --git a/R/plotBRICKcalib.R b/R/plotBRICKCalib.R similarity index 97% rename from R/plotBRICKcalib.R rename to R/plotBRICKCalib.R index cd47b2c..360a590 100644 --- a/R/plotBRICKcalib.R +++ b/R/plotBRICKCalib.R @@ -62,7 +62,7 @@ plotBRICKCalib <- function(path = ".", cal = "BRICK_calibration_report.csv", render( file.path(finalOutputDir, "plotsCalibration.Rmd"), output_dir = finalOutputDir, - output_file = paste0("CES_calibration_report_", outName, ".pdf"), + output_file = paste0("BRICK_calibration_report_", outName, ".pdf"), output_format = "pdf_document", params = yamlParams ) diff --git a/README.md b/README.md index bbc4ac9..a85e4b8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Reporting package for BRICK -R package **reportbrick**, version **0.4.1** +R package **reportbrick**, version **0.4.2** [![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) @@ -38,7 +38,7 @@ In case of questions / problems please contact Robin Hasse . +Hasse R, Rosemann R (2024). _reportbrick: Reporting package for BRICK_. R package version 0.4.2, . 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 and Ricarda Rosemann}, year = {2024}, - note = {R package version 0.4.1}, + note = {R package version 0.4.2}, url = {https://github.com/pik-piam/reportbrick}, } ``` diff --git a/inst/plotsCalibrationReporting/plotsCalibration.Rmd b/inst/plotsCalibrationReporting/plotsCalibration.Rmd index 0182072..6da5c1a 100644 --- a/inst/plotsCalibrationReporting/plotsCalibration.Rmd +++ b/inst/plotsCalibrationReporting/plotsCalibration.Rmd @@ -9,14 +9,18 @@ output: params: docTitle: "BRICK calibration report" cal: "BRICK_calibration_report.csv" - path: "C:\\Users\\ricardar\\Documents\\Results\\BRICK\\calibration-tests\\extrElec-vin\\lowEhp1-2010-30Iter0_1A" + path: "" scenNames: NULL - savePlots: TRUE + savePlots: false name: "" --- ```{r setup, include=FALSE} -library(dplyr) #nolint: undesirable_function_linter. + +# nolint start: undesirable_function_linter. +library(dplyr, include.only = c("%>%", "across", "any_of", ".data", "filter", "mutate", + "select", "where")) +# nolint end knitr::opts_chunk$set( echo = FALSE, @@ -34,8 +38,8 @@ filePath <- file.path(params$path, params$cal) # Check if at least one file in the given paths exists if (!any(file.exists(filePath))) { - message("No BRICK_calibration_report.csv file found", - "BRICK_calibration_calibration.csv is normally produced during calibration runs.") + message("No BRICK_calibration_report.csv file found.\n", + "BRICK_calibration_report.csv is normally produced during calibration runs.") knitr::knit_exit() } @@ -50,18 +54,26 @@ outPath <- dirname(filePath[1]) # Standard procedure to write a calibration plot .createCalibrationPlot <- function(data, varName, outPath, outName = "", - color = NULL, savePlots = FALSE) { + color = NULL, facets = c("loc", "typ"), + yToZero = TRUE, savePlots = FALSE) { # Extract the data plData <- data %>% - filter(.data[["variable"]] == varName) %>% + filter(.data[["variable"]] %in% varName) %>% select(where(~ any(!is.na(.x)))) + # Read color map if available and rename corresponding entries + if (!is.null(color)) { + colorMap <- unlist(readBrickSets(NULL)[[color]][["elements"]]) + plData <- plData %>% + mutate(across(any_of(color), ~ factor(colorMap[.x], levels = colorMap))) + } # Create the plots plList <- mip::mipIterations(plData, returnGgplots = TRUE, xAxis = "iteration", - color = color, facets = c("loc", "typ"), + color = color, facets = facets, slider = NULL, facetScales = "free") # Modify, save and show the plots purrr::walk(plList, function(pl) { - pl <- pl + ggplot2::expand_limits(y = 0) + if (isTRUE(yToZero)) pl <- pl + ggplot2::expand_limits(y = 0) + if (!is.null(color)) pl <- pl + ggplot2::scale_colour_manual(values = mip::plotstyle(colorMap)) # Currently, this overwrites previous plots so that only the last one remains if (isTRUE(savePlots)) { ggplot2::ggsave(file.path(outPath, paste0(paste(varName, outName, sep = "_"), ".png")), pl) diff --git a/man/plotBRICKCalib.Rd b/man/plotBRICKCalib.Rd index 1244538..12e1b84 100644 --- a/man/plotBRICKCalib.Rd +++ b/man/plotBRICKCalib.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/plotBRICKcalib.R +% Please edit documentation in R/plotBRICKCalib.R \name{plotBRICKCalib} \alias{plotBRICKCalib} \title{Render the BRICK calibration plotting routine}