Label virtual corpora by the names they were given

Passing c(before = ..., since = ...) said what the two corpora are to be
called, and only collocationAnalysis() listened. frequencyQuery() dropped
the names in the expand_grid() it builds its queries from and returned no
label at all; corpusStats() let them become row names, which the first
bind_rows() throws away; collocationScoreQuery() ignored them and derived
a label from the corpus definitions instead, so that the pair above came
out as "1990 & pubDat..." and "2010".

All three now prefer the names, falling back to queryStringToLabel()
where a vector is named only in part, as collocationAnalysis() has been
doing. A vector without names is left alone: no label column appears
where there is nothing to put in it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Change-Id: I72c7c8d5f14b649df853cae94a4d90c0be19d1f4
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
index a8372e3..77774c8 100644
--- a/R/KorAPQuery.R
+++ b/R/KorAPQuery.R
@@ -215,14 +215,20 @@
            as.df = FALSE,
            context = NULL) {
     if (length(query) > 1 || length(vc) > 1) {
+      # expand_grid() and tibble() drop the names of vc, so the labels the
+      # caller gave their virtual corpora are carried along as a column
+      vcLabel <- vcLabels(vc)
       grid <- if (expand) expand_grid(query = query, vc = vc) else tibble(query = query, vc = vc)
+      if (!is.null(vcLabel)) {
+        grid$label <- if (expand) rep(vcLabel, times = length(query)) else vcLabel
+      }
 
       # Initialize timing variables for ETA calculation
       total_queries <- nrow(grid)
       current_query <- 0
       start_time <- Sys.time()
 
-      results <- purrr::pmap(grid, function(query, vc, ...) {
+      results <- purrr::pmap(grid, function(query, vc, label = NULL, ...) {
         current_query <<- current_query + 1
 
         # Execute the single query directly (avoiding recursive call)
@@ -297,6 +303,9 @@
           webUIRequestUrl = webUIRequestUrl,
           stringsAsFactors = FALSE
         )
+        if (!is.null(label)) {
+          result <- tibble::add_column(result, label = label, .after = "vc")
+        }
 
         return(result)
       })