Fix ci compatibility and error in as.alternative cospusQuery
Change-Id: I45817afd9bbf57f72bfbcd9c638a9d40b8e79055
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
index 805d7d7..b6da9a1 100644
--- a/R/KorAPQuery.R
+++ b/R/KorAPQuery.R
@@ -84,7 +84,7 @@
#'
#' @importFrom urltools url_encode
#' @importFrom purrr pmap
-#' @importFrom dplyr bind_rows
+#' @importFrom dplyr bind_rows group_by
#'
#' @param kco [KorAPConnection()] object (obtained e.g. from `KorAPConnection()`
#' @param query string that contains the corpus query. The query language depends on the `ql` parameter. Either `query` must be provided or `KorAPUrl`.
@@ -776,12 +776,12 @@
function(kco, query, vc = "", conf.level = 0.95, as.alternatives = FALSE, ...) {
(if (as.alternatives) {
corpusQuery(kco, query, vc, metadataOnly = TRUE, as.df = TRUE, ...) |>
- group_by(vc) %>%
+ group_by(vc) |>
mutate(total = sum(totalResults))
} else {
corpusQuery(kco, query, vc, metadataOnly = TRUE, as.df = TRUE, ...) |>
mutate(total = corpusStats(kco, vc = vc, as.df = TRUE)$tokens)
- }) %>%
+ }) |>
ci(conf.level = conf.level)
}
)
diff --git a/R/ci.R b/R/ci.R
index 032b677..e770bbc 100644
--- a/R/ci.R
+++ b/R/ci.R
@@ -42,8 +42,11 @@
x <- enquo(x)
N <- enquo(N)
+ # Ensure df is ungrouped for compatibility with grouped data
+ df <- df |> ungroup()
+
# Add row index to preserve original order
- df <- df %>% mutate(.row_index = row_number())
+ df <- df |> mutate(.row_index = row_number())
# Initialize result with all NA values
result <- df %>%