Skip to content

Commit

Permalink
Merge pull request #76 from 0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q/dev/quit…
Browse files Browse the repository at this point in the history
…teSort_alphabetical_levels

have quitteSort() sort factor levels alphabetically
  • Loading branch information
0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q authored Oct 18, 2023
2 parents b4289f2 + ca0c508 commit a5b69f0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -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'
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: '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:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre")),
person("Nico", "Bauer", , "[email protected]", role = "aut"),
Expand Down
15 changes: 11 additions & 4 deletions R/quitteSort.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -47,7 +47,7 @@ In case of questions / problems please contact Michaja Pehl <michaja.pehl@pik-po

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

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.3124.0, <https://github.com/pik-piam/quitte>.
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, <https://github.com/pik-piam/quitte>.

A BibTeX entry for LaTeX users is

Expand All @@ -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},
}
```
4 changes: 2 additions & 2 deletions tests/testthat/test-quitteSort.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit a5b69f0

Please sign in to comment.