From 3791270366a2aaf38bb60f26bab30f87d6e8f8b9 Mon Sep 17 00:00:00 2001 From: patrickbarks Date: Thu, 21 Mar 2024 12:10:01 +0100 Subject: [PATCH] fix bug causing error when validate_cond had more than 1 conditional col --- .Rbuildignore | 1 + DESCRIPTION | 2 +- NAMESPACE | 1 + R/qxl.R | 11 +++++------ 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 315f347..f0a19e5 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,5 +1,6 @@ ^qxl\.Rproj$ ^\.Rproj\.user$ +^archive$ ^data-raw$ ^README\.Rmd$ ^LICENSE\.md$ diff --git a/DESCRIPTION b/DESCRIPTION index a14bbc9..8aa0811 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,9 +22,9 @@ Imports: readxl, dplyr, rlang, + tidyr, lubridate Suggests: testthat (>= 3.0.0), tibble, - tidyr, covr diff --git a/NAMESPACE b/NAMESPACE index 880ab6b..e77a49c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -36,3 +36,4 @@ importFrom(rlang,eval_tidy) importFrom(rlang,is_quosure) importFrom(rlang,quo_get_expr) importFrom(stats,setNames) +importFrom(tidyr,unnest) diff --git a/R/qxl.R b/R/qxl.R index c5d2e23..8c04e62 100644 --- a/R/qxl.R +++ b/R/qxl.R @@ -274,6 +274,7 @@ qxl <- function(x, #' @noRd #' @import openxlsx #' @importFrom stats setNames +#' @importFrom tidyr unnest #' @importFrom dplyr everything select mutate arrange relocate `%>%` all_of #' bind_rows across cur_group_id group_by ungroup n summarize left_join #' distinct @@ -614,14 +615,12 @@ qxl_ <- function(x, if (!is.null(validate_cond_all)) { - validate_cond_all_df <- expand.grid( - x = sort(unique(x[[cols_cond]])), - y = validate_cond_all - ) %>% + validate_cond_all_df <- unique(x[,cols_cond, drop = FALSE]) %>% + mutate(replacement = list(validate_cond_all)) %>% + tidyr::unnest("replacement") %>% stats::setNames(c(cols_cond, col_validation)) - validate_cond_df <- validate_cond_df %>% - bind_rows(validate_cond_all_df) %>% + validate_cond_df <- bind_rows(validate_cond_df, validate_cond_all_df) %>% arrange(across(all_of(cols_cond))) }