💄 Start switching to base R pipe
Change-Id: I9a7cadb089e150deb1e58f33b8944ea789cd612f
diff --git a/R/collocationAnalysis.R b/R/collocationAnalysis.R
index 378fd0a..ca487da 100644
--- a/R/collocationAnalysis.R
+++ b/R/collocationAnalysis.R
@@ -53,9 +53,9 @@
#' \dontrun{
#'
#' # Find top collocates of "Packung" inside and outside the sports domain.
-#' KorAPConnection(verbose = TRUE) %>%
+#' KorAPConnection(verbose = TRUE) |>
#' collocationAnalysis("Packung", vc=c("textClass=sport", "textClass!=sport"),
-#' leftContextSize=1, rightContextSize=1, topCollocatesLimit=20) %>%
+#' leftContextSize=1, rightContextSize=1, topCollocatesLimit=20) |>
#' dplyr::filter(logDice >= 5)
#' }
#'
@@ -63,7 +63,7 @@
#'
#' # Identify the most prominent light verb construction with "in ... setzen".
#' # Note that, currently, the use of focus function disallows exactFrequencies.
-#' KorAPConnection(verbose = TRUE) %>%
+#' KorAPConnection(verbose = TRUE) |>
#' collocationAnalysis("focus(in [tt/p=NN] {[tt/l=setzen]})",
#' leftContextSize=1, rightContextSize=0, exactFrequencies=FALSE, topCollocatesLimit=20)
#' }
@@ -124,7 +124,7 @@
localStopwords = localStopwords,
seed = seed,
expand = expand,
- ...) ) %>%
+ ...) ) |>
bind_rows()
} else {
set.seed(seed)
@@ -142,8 +142,8 @@
)
if (nrow(candidates) > 0) {
- candidates <- candidates %>%
- filter(frequency >= minOccur) %>%
+ candidates <- candidates |>
+ filter(frequency >= minOccur) |>
slice_head(n=topCollocatesLimit)
collocationScoreQuery(
kco,
@@ -164,7 +164,7 @@
}
}
if (maxRecurse > 0 & length(result) > 0 && any(!!thresholdScore >= threshold)) {
- recurseWith <- result %>%
+ recurseWith <- result |>
filter(!!as.name(thresholdScore) >= threshold)
result <- collocationAnalysis(
kco,
@@ -262,10 +262,10 @@
)
}
log_info(verbose, paste("Aggregating", length(oldTable$word), "tokens\n"))
- oldTable %>%
- group_by(word) %>%
- mutate(word = dplyr::case_when(ignoreCollocateCase ~ tolower(word), TRUE ~ word)) %>%
- summarise(frequency=sum(frequency), .groups = "drop") %>%
+ oldTable |>
+ group_by(word) |>
+ mutate(word = dplyr::case_when(ignoreCollocateCase ~ tolower(word), TRUE ~ word)) |>
+ summarise(frequency=sum(frequency), .groups = "drop") |>
arrange(desc(frequency))
} else {
stopwordsTable <- dplyr::tibble(word=stopwords)
@@ -281,11 +281,11 @@
if(length(left) + length(right) == 0) {
oldTable
} else {
- table(c(left, right)) %>%
- dplyr::as_tibble(.name_repair = "minimal") %>%
- dplyr::rename(word = 1, frequency = 2) %>%
- dplyr::filter(str_detect(word, collocateFilterRegex)) %>%
- dplyr::anti_join(stopwordsTable, by="word") %>%
+ table(c(left, right)) |>
+ dplyr::as_tibble(.name_repair = "minimal") |>
+ dplyr::rename(word = 1, frequency = 2) |>
+ dplyr::filter(str_detect(word, collocateFilterRegex)) |>
+ dplyr::anti_join(stopwordsTable, by="word") |>
dplyr::bind_rows(oldTable)
}
}
@@ -323,10 +323,10 @@
)
}
log_info(verbose, paste("Aggregating", length(oldTable$word), "tokens\n"))
- oldTable %>%
- group_by(word) %>%
- mutate(word = dplyr::case_when(ignoreCollocateCase ~ tolower(word), TRUE ~ word)) %>%
- summarise(frequency=sum(frequency), .groups = "drop") %>%
+ oldTable |>
+ group_by(word) |>
+ mutate(word = dplyr::case_when(ignoreCollocateCase ~ tolower(word), TRUE ~ word)) |>
+ summarise(frequency=sum(frequency), .groups = "drop") |>
arrange(desc(frequency))
} else {
stopwordsTable <- dplyr::tibble(word=stopwords)
@@ -351,11 +351,11 @@
if(is.na(left[1]) || is.na(right[1]) || length(left) + length(right) == 0) {
oldTable
} else {
- table(c(left, right)) %>%
- dplyr::as_tibble(.name_repair = "minimal") %>%
- dplyr::rename(word = 1, frequency = 2) %>%
- dplyr::filter(str_detect(word, collocateFilterRegex)) %>%
- dplyr::anti_join(stopwordsTable, by="word") %>%
+ table(c(left, right)) |>
+ dplyr::as_tibble(.name_repair = "minimal") |>
+ dplyr::rename(word = 1, frequency = 2) |>
+ dplyr::filter(str_detect(word, collocateFilterRegex)) |>
+ dplyr::anti_join(stopwordsTable, by="word") |>
dplyr::bind_rows(oldTable)
}
}
@@ -487,8 +487,8 @@
ignoreCollocateCase = ignoreCollocateCase,
stopwords = stopwords,
...,
- verbose = kco@verbose) %>%
- mutate(frequency = frequency * q@totalResults / min(q@totalResults, searchHitsSampleLimit)) %>%
+ verbose = kco@verbose) |>
+ mutate(frequency = frequency * q@totalResults / min(q@totalResults, searchHitsSampleLimit)) |>
filter(frequency >= minOccur)
}
}
diff --git a/R/collocationScoreQuery.R b/R/collocationScoreQuery.R
index 6ac1a98..bcff325 100644
--- a/R/collocationScoreQuery.R
+++ b/R/collocationScoreQuery.R
@@ -33,13 +33,13 @@
#' @examples
#' \dontrun{
#'
-#' KorAPConnection(verbose = TRUE) %>%
+#' KorAPConnection(verbose = TRUE) |>
#' collocationScoreQuery("Grund", "triftiger")
#' }
#'
#' \dontrun{
#'
-#' KorAPConnection(verbose = TRUE) %>%
+#' KorAPConnection(verbose = TRUE) |>
#' collocationScoreQuery("Grund", c("guter", "triftiger"),
#' scoreFunctions = list(localMI = function(O1, O2, O, N, E, window_size) { O * log2(O/E) }) )
#' }
@@ -48,11 +48,11 @@
#'
#' library(highcharter)
#' library(tidyr)
-#' KorAPConnection(verbose = TRUE) %>%
+#' KorAPConnection(verbose = TRUE) |>
#' collocationScoreQuery("Team", "agil", vc = paste("pubDate in", c(2014:2018)),
-#' lemmatizeNodeQuery = TRUE, lemmatizeCollocateQuery = TRUE) %>%
-#' pivot_longer(14:last_col(), names_to = "measure", values_to = "score") %>%
-#' hchart(type="spline", hcaes(label, score, group=measure)) %>%
+#' lemmatizeNodeQuery = TRUE, lemmatizeCollocateQuery = TRUE) |>
+#' pivot_longer(14:last_col(), names_to = "measure", values_to = "score") |>
+#' hchart(type="spline", hcaes(label, score, group=measure)) |>
#' hc_add_onclick_korap_search()
#' }
#'
@@ -202,8 +202,8 @@
korapUrl <- combined_df$webUIRequestUrl[1] |> httr2::url_modify(query="")
# Group by collocate and summarize
- combined_df %>%
- group_by(collocate, O2, N) %>%
+ combined_df |>
+ group_by(collocate, O2, N) |>
summarise(
O = sum(O) - smoothingConstant * (n()-1),
O1 = sum(O1) - smoothingConstant * (n()-1),
@@ -219,7 +219,7 @@
query = paste(query, collapse = " | "),
webUIRequestUrl = buildWebUIRequestUrlFromString(korapUrl, query = paste(query, collapse = " | "), vc = first(vc)),
across(everything(), first),
- ) %>%
+ ) |>
ungroup()
}