From e6c3eee45431747663de82df9431b48405a6291d Mon Sep 17 00:00:00 2001 From: orichters Date: Fri, 27 Sep 2024 18:21:20 +0200 Subject: [PATCH 1/2] show which filenames let as.quitte fail --- R/as.quitte.R | 10 +++++----- tests/testthat/test-as.quitte.R | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/R/as.quitte.R b/R/as.quitte.R index 759c0f5..19708d3 100644 --- a/R/as.quitte.R +++ b/R/as.quitte.R @@ -32,12 +32,12 @@ as.quitte <- function(x, periodClass = "integer", addNA = FALSE, na.rm = FALSE) #' @export as.quitte.character <- function(x, periodClass = "integer", addNA = FALSE, na.rm = FALSE) { # nolint - if (all(file.exists(x) & grepl("\\.(mif|csv|rds|xlsx?)$", x))) + welldefined <- file.exists(x) & grepl("\\.(mif|csv|rds|xlsx?)$", x) + if (all(welldefined)) return(as.quitte(read.quitte(x, sep = NULL), periodClass = periodClass, addNA = addNA, na.rm = na.rm)) - stop( - "Provided character cannot be converted to quitte as it does not seem to be a valid file path!" - ) + stop("Provided character cannot be converted to quitte as those do not seem to be a valid file path:", + paste(x[! welldefined], collapse = ", ")) } #' @method as.quitte quitte @@ -242,7 +242,7 @@ as.quitte.list <- function(x, periodClass = "integer", addNA = FALSE, na.rm = FA #' @method as.quitte NULL #' @export as.quitte.NULL <- function(x, periodClass = "integer", addNA = FALSE, na.rm = FALSE) { # nolint - return(filter(as.quitte(as_tibble(as.quitte(data.frame(value = 0), periodClass = periodClass))), .data$value > 1)) + return(droplevels(filter(as.quitte(as_tibble(as.quitte(data.frame(value = 0), periodClass = periodClass))), .data$value > 1))) } qaddNA <- function(x) { diff --git a/tests/testthat/test-as.quitte.R b/tests/testthat/test-as.quitte.R index 5d79ef1..5de4723 100644 --- a/tests/testthat/test-as.quitte.R +++ b/tests/testthat/test-as.quitte.R @@ -92,6 +92,14 @@ test_that( { expect_true(is.quitte(as.quitte(NULL))) expect_equal(nrow(as.quitte(NULL)), 0) + expect_equal(length(levels(as.quitte(NULL)$model)), 0) + } +) + +test_that( + 'as.quitte fails on non-supported filename', + { + expect_error(as.quitte('unknownfiletype.§§$%')) } ) From 3bdc731eaf41c4e7262ea72006f09f1ace09a87e Mon Sep 17 00:00:00 2001 From: orichters Date: Fri, 27 Sep 2024 18:24:11 +0200 Subject: [PATCH 2/2] typo, better test, buildLibrary --- .buildlibrary | 2 +- CITATION.cff | 4 ++-- DESCRIPTION | 4 ++-- R/as.quitte.R | 2 +- README.md | 6 +++--- tests/testthat/test-as.quitte.R | 3 ++- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index a95cd36..0224b7b 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '626216492' +ValidationKey: '627240389' 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 3977706..974a2b6 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.3137.2 -date-released: '2024-08-26' +version: 0.3137.3 +date-released: '2024-09-27' 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 093e7af..a562d17 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.3137.2 -Date: 2024-08-26 +Version: 0.3137.3 +Date: 2024-09-27 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/as.quitte.R b/R/as.quitte.R index 19708d3..c42445b 100644 --- a/R/as.quitte.R +++ b/R/as.quitte.R @@ -36,7 +36,7 @@ as.quitte.character <- function(x, periodClass = "integer", addNA = FALSE, na.rm if (all(welldefined)) return(as.quitte(read.quitte(x, sep = NULL), periodClass = periodClass, addNA = addNA, na.rm = na.rm)) - stop("Provided character cannot be converted to quitte as those do not seem to be a valid file path:", + stop("Provided character cannot be converted to quitte as those do not seem to be a valid file path: ", paste(x[! welldefined], collapse = ", ")) } diff --git a/README.md b/README.md index 68388d2..4307713 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.3137.2** +R package **quitte**, version **0.3137.3** [![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 (2024). _quitte: Bits and pieces of code to use with quitte-style data frames_. R package version 0.3137.3, . 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 = {2024}, - note = {R package version 0.3137.2}, + note = {R package version 0.3137.3}, url = {https://github.com/pik-piam/quitte}, } ``` diff --git a/tests/testthat/test-as.quitte.R b/tests/testthat/test-as.quitte.R index 5de4723..e60885a 100644 --- a/tests/testthat/test-as.quitte.R +++ b/tests/testthat/test-as.quitte.R @@ -99,7 +99,8 @@ test_that( test_that( 'as.quitte fails on non-supported filename', { - expect_error(as.quitte('unknownfiletype.§§$%')) + expect_error(as.quitte('unknownfiletype.§§$%'), + 'do not seem to be a valid file path: unknownfiletype.§§$%', fixed = TRUE) } )