diff --git a/.buildlibrary b/.buildlibrary index f2f5781..a43b857 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '29421782' +ValidationKey: '29444544' 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 3f3eb02..f63647d 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: 'mip: Comparison of multi-model runs' -version: 0.148.7 -date-released: '2024-03-04' +version: 0.148.8 +date-released: '2024-03-06' abstract: Package contains generic functions to produce comparison plots of multi-model runs. authors: diff --git a/DESCRIPTION b/DESCRIPTION index 7f8cb71..3a946cc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mip Title: Comparison of multi-model runs -Version: 0.148.7 -Date: 2024-03-04 +Version: 0.148.8 +Date: 2024-03-06 Authors@R: c( person("David", "Klein", , "dklein@pik-potsdam.de", role = c("aut", "cre")), person("Jan Philipp", "Dietrich", , "dietrich@pik-potsdam.de", role = "aut"), diff --git a/NAMESPACE b/NAMESPACE index c4a0f14..03bbedf 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -195,6 +195,7 @@ importFrom(stats,na.omit) importFrom(stats,reshape) importFrom(stats,runif) importFrom(stringr,str_extract) +importFrom(tidyr,all_of) importFrom(tidyr,crossing) importFrom(tidyr,drop_na) importFrom(tidyr,pivot_wider) diff --git a/R/plotPercentiles.R b/R/plotPercentiles.R index ef6092c..a42c899 100644 --- a/R/plotPercentiles.R +++ b/R/plotPercentiles.R @@ -27,25 +27,31 @@ #' } #' @section Example Plot: #' \if{html}{\figure{plotPercentiles1.png}{Atmospheric CO2 concentrations for all scenarios available in the data}} -#' @importFrom dplyr filter mutate vars +#' @importFrom dplyr filter mutate vars select #' @importFrom reshape2 melt #' @importFrom stringr str_extract -#' @importFrom tidyr pivot_wider +#' @importFrom tidyr pivot_wider all_of #' @importFrom ggplot2 ggplot geom_line geom_ribbon facet_wrap facet_grid theme ylab #' @export plotPercentiles <- function(df, scenarios = NULL, variables = NULL) { - + # Dropped "model" from Necessary columns + necessaryCols <- c("scenario", "region", "variable", "unit", "period", "value") # In the quitte data frame all percentiles are given as individual variables. Manipulate input data frame such that - # all percentiles of a given quantity are transformed to individual columns. Variable names in the quitte data frame - # follow the format "Any|Variable|5.0th Percentile". The regular expressions below divide the variable name into the - # prefix and the percentile specifier + # all percentiles of a given quantity are transformed to individual columns data <- df %>% + # Drop NA values as.quitte(na.rm = TRUE) %>% + # Only use necessary columns. The .data-prefix in col names was deprecated in tidyselect since v1.2.0. + select(all_of(necessaryCols)) %>% + # Variable names in the quitte data frame follow the format "Any|Variable|5.0th Percentile". The regular + # expressions below divide the variable name into the prefix and the percentile specifier mutate( "percentile" = stringr::str_extract(.data$variable, "[^\\|]+?$"), "variable" = gsub("\\|[^\\|]+$", "", .data$variable) ) %>% + # Remove all non-percentile variables filter(grepl(" Percentile$", .data$percentile)) %>% + # Pivot data such that percentiles are transformed to individual columns pivot_wider( names_from = "percentile", values_from = "value" diff --git a/README.md b/README.md index f4e7eae..65a8c9d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Comparison of multi-model runs -R package **mip**, version **0.148.7** +R package **mip**, version **0.148.8** [![CRAN status](https://www.r-pkg.org/badges/version/mip)](https://cran.r-project.org/package=mip) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1158586.svg)](https://doi.org/10.5281/zenodo.1158586) [![R build status](https://github.com/pik-piam/mip/workflows/check/badge.svg)](https://github.com/pik-piam/mip/actions) [![codecov](https://codecov.io/gh/pik-piam/mip/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mip) [![r-universe](https://pik-piam.r-universe.dev/badges/mip)](https://pik-piam.r-universe.dev/builds) @@ -47,7 +47,7 @@ In case of questions / problems please contact David Klein , R package version 0.148.7, . +Klein D, Dietrich J, Baumstark L, Humpenoeder F, Stevanovic M, Wirth S, Führlich P, Richters O, Rüter T (2024). _mip: Comparison of multi-model runs_. doi: 10.5281/zenodo.1158586 (URL: https://doi.org/10.5281/zenodo.1158586), R package version 0.148.8, . A BibTeX entry for LaTeX users is @@ -56,7 +56,7 @@ A BibTeX entry for LaTeX users is title = {mip: Comparison of multi-model runs}, author = {David Klein and Jan Philipp Dietrich and Lavinia Baumstark and Florian Humpenoeder and Miodrag Stevanovic and Stephen Wirth and Pascal Führlich and Oliver Richters and Tonn Rüter}, year = {2024}, - note = {R package version 0.148.7}, + note = {R package version 0.148.8}, doi = {10.5281/zenodo.1158586}, url = {https://github.com/pik-piam/mip}, } diff --git a/man/mip-package.Rd b/man/mip-package.Rd index 6ac9051..98e5439 100644 --- a/man/mip-package.Rd +++ b/man/mip-package.Rd @@ -3,7 +3,6 @@ \docType{package} \name{mip-package} \alias{mip-package} -\alias{_PACKAGE} \alias{mip} \title{The MIP R package} \description{