diff --git a/.buildlibrary b/.buildlibrary index 65e500a..3478888 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '615880016' +ValidationKey: '615930987' 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 24db312..77b824c 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.3128.2 -date-released: '2023-11-27' +version: 0.3128.3 +date-released: '2023-11-28' 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 73409af..0007df4 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.3128.2 -Date: 2023-11-27 +Version: 0.3128.3 +Date: 2023-11-28 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/cartesian.R b/R/cartesian.R index 627ff13..2026535 100644 --- a/R/cartesian.R +++ b/R/cartesian.R @@ -1,4 +1,4 @@ -#' Generate cartesian product from to character vectors +#' Generate Cartesian product from character vectors #' #' @param ... objects that can be coerced to character vectors #' @param sep a character string that will separate the elements of `...` in the @@ -14,25 +14,14 @@ #' #' @export cartesian <- function(..., sep = '.') { - dots <- list(...) + if (0 == length(dots <- list(...))) + return(NULL) - L <- lengths(dots) + v <- as.character(dots[[1]]) + for (i in dots[-1]) + v <- paste(rep(v, each = length(i)), + rep(as.character(i), times = length(v)), + sep = sep) - apply( - X = sapply( - X = seq_along(dots), - FUN = function(i) { - # lengths of dots elements before i (excluding) - times_slice <- L[seq_len(i - 1)] - # lengths of dot elements after i (excluding) - each_slice <- L[setdiff(seq_along(dots), seq_len(i))] - - rep(rep(dots[[i]], times = prod(times_slice)), - each = prod(each_slice)) - } - ), - MARGIN = 1, - FUN = paste, - collapse = sep - ) + return(v) } diff --git a/README.md b/README.md index 7b4d8d2..15bc9ff 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.3128.2** +R package **quitte**, version **0.3128.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 (2023). _quitte: Bits and pieces of code to use with quitte-style data frames_. R package version 0.3128.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 = {2023}, - note = {R package version 0.3128.2}, + note = {R package version 0.3128.3}, url = {https://github.com/pik-piam/quitte}, } ``` diff --git a/tests/testthat/test-cartesian.R b/tests/testthat/test-cartesian.R index 6d998bd..52075f1 100644 --- a/tests/testthat/test-cartesian.R +++ b/tests/testthat/test-cartesian.R @@ -1,5 +1,5 @@ test_that( - desc = 'cartesian() generates correct combinations', + desc = 'cartesian(...) generates correct combinations', code = { expect_equal( object = cartesian(1:2), @@ -18,3 +18,9 @@ test_that( '2.3.7', '2.3.8', '2.3.9', '2.4.7', '2.4.8', '2.4.9', '2.5.7', '2.5.8', '2.5.9', '2.6.7', '2.6.8', '2.6.9')) }) + +test_that( + desc = 'cartesian() returns NULL', + code = { + expect_null(object = cartesian()) + })