-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from orichters/smallfix
add quitteSort to get consistent sorting
- Loading branch information
Showing
10 changed files
with
78 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.3122.0 | ||
Date: 2023-09-19 | ||
Version: 0.3123.0 | ||
Date: 2023-10-09 | ||
Authors@R: c( | ||
person("Michaja", "Pehl", , "[email protected]", role = c("aut", "cre")), | ||
person("Nico", "Bauer", , "[email protected]", role = "aut"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#' Sorts a quitte object in a standardized way: | ||
#' model -> scenario -> variable -> unit -> region -> period | ||
#' | ||
#' @param x A quitte object | ||
#' | ||
#' @author Oliver Richters | ||
#' | ||
#' @importFrom dplyr arrange relocate | ||
#' | ||
#' @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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
context('quitteSort()') | ||
|
||
test_that('quitteSort works', { | ||
for (qe in list(quitte_example_dataAR6, quitte_example_data)) { | ||
qe <- droplevels(as.quitte(qe, na.rm = TRUE)) | ||
qes <- droplevels(quitteSort(qe)) | ||
for (type in colnames(qe)) { | ||
expect_equal(sort(unique_or_levels(qe[[type]])), sort(unique_or_levels(qes[[type]]))) | ||
} | ||
expect_identical(nrow(qe), nrow(qes)) | ||
# move model column to the end | ||
qewrong <- relocate(qes, model, .after = value) | ||
expect_false(identical(qes, qewrong)) | ||
expect_identical(qes, quitteSort(qewrong)) | ||
# move first region to the end | ||
qewrong <- bind_rows( | ||
qes %>% filter(first(region) != region), | ||
qes %>% filter(first(region) == region) | ||
) | ||
expect_false(identical(qes, qewrong)) | ||
expect_identical(qes, quitteSort(qewrong)) | ||
} | ||
}) |