diff --git a/.buildlibrary b/.buildlibrary index a779412..66c2443 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '613522360' +ValidationKey: '6.14e+08' 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 2c4f301..b964109 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: 'quitte: Bits and pieces of code to use with quitte-style data frames' -version: 0.3124.0 -date-released: '2023-10-09' +version: 0.3125.0 +date-released: '2023-10-18' abstract: A collection of functions for easily dealing with quitte-style data frames, doing multi-model comparisons and plots. authors: diff --git a/DESCRIPTION b/DESCRIPTION index 9c730f4..e5cb620 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: quitte Title: Bits and pieces of code to use with quitte-style data frames -Version: 0.3124.0 -Date: 2023-10-09 +Version: 0.3125.0 +Date: 2023-10-18 Authors@R: c( person("Michaja", "Pehl", , "pehl@pik-potsdam.de", role = c("aut", "cre")), person("Nico", "Bauer", , "nicolasb@pik-potsdam.de", role = "aut"), diff --git a/R/quitteSort.R b/R/quitteSort.R index aae5213..ca08a1d 100644 --- a/R/quitteSort.R +++ b/R/quitteSort.R @@ -10,9 +10,16 @@ #' @return the sorted quitte object #' @export quitteSort <- function(x) { - model <- scenario <- region <- variable <- unit <- period <- NULL x <- as.quitte(x) %>% - relocate(model, scenario, region, variable, unit, period) %>% - arrange(model, scenario, variable, unit, region, period) %>% - return() + relocate('model', 'scenario', 'region', 'variable', 'unit', 'period') + + for (col in names(which('factor' == sapply(x, class)))) { + x <- x %>% + mutate( + !!sym(col) := factor(.data[[col]], levels = sort(levels(.data[[col]])))) + } + + x %>% + arrange(.data$model, .data$scenario, .data$region, .data$variable, + .data$unit, .data$period) } diff --git a/README.md b/README.md index 268bd55..3cc5bde 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Bits and pieces of code to use with quitte-style data frames -R package **quitte**, version **0.3124.0** +R package **quitte**, version **0.3125.0** [![CRAN status](https://www.r-pkg.org/badges/version/quitte)](https://cran.r-project.org/package=quitte) [![R build status](https://github.com/pik-piam/quitte/workflows/check/badge.svg)](https://github.com/pik-piam/quitte/actions) [![codecov](https://codecov.io/gh/pik-piam/quitte/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/quitte) [![r-universe](https://pik-piam.r-universe.dev/badges/quitte)](https://pik-piam.r-universe.dev/builds) @@ -47,7 +47,7 @@ In case of questions / problems please contact Michaja Pehl . +Pehl M, Bauer N, Hilaire J, Levesque A, Luderer G, Schultes A, Dietrich J, Richters O (2023). _quitte: Bits and pieces of code to use with quitte-style data frames_. R package version 0.3125.0, . A BibTeX entry for LaTeX users is @@ -56,7 +56,7 @@ A BibTeX entry for LaTeX users is title = {quitte: Bits and pieces of code to use with quitte-style data frames}, author = {Michaja Pehl and Nico Bauer and Jérôme Hilaire and Antoine Levesque and Gunnar Luderer and Anselm Schultes and Jan Philipp Dietrich and Oliver Richters}, year = {2023}, - note = {R package version 0.3124.0}, + note = {R package version 0.3125.0}, url = {https://github.com/pik-piam/quitte}, } ``` diff --git a/tests/testthat/test-quitteSort.R b/tests/testthat/test-quitteSort.R index ad8b209..26e4f91 100644 --- a/tests/testthat/test-quitteSort.R +++ b/tests/testthat/test-quitteSort.R @@ -14,8 +14,8 @@ test_that('quitteSort works', { expect_identical(qes, quitteSort(qewrong)) # move first region to the end qewrong <- bind_rows( - qes %>% filter(first(region) != region), - qes %>% filter(first(region) == region) + qes %>% filter(first(region) != region), + qes %>% filter(first(region) == region) ) expect_false(identical(qes, qewrong)) expect_identical(qes, quitteSort(qewrong))