💄 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()
}
diff --git a/Readme.md b/Readme.md
index f90764d..05cc1b2 100644
--- a/Readme.md
+++ b/Readme.md
@@ -21,7 +21,7 @@
```R
library(RKorAPClient)
-KorAPConnection(verbose=TRUE) %>% corpusQuery("Hello world") %>% fetchAll()
+KorAPConnection(verbose=TRUE) |> corpusQuery("Hello world") |> fetchAll()
```
### Frequencies over time and domains using ggplot2
@@ -49,8 +49,8 @@
years = c(1980:2010)
as.alternatives = TRUE
vc = "textType = /Zeit.*/ & pubDate in"
-KorAPConnection(verbose=T) %>%
- frequencyQuery(query, paste(vc, years), as.alternatives = as.alternatives) %>%
+KorAPConnection(verbose=T) |>
+ frequencyQuery(query, paste(vc, years), as.alternatives = as.alternatives) |>
hc_freq_by_year_ci(as.alternatives)
```
@@ -62,7 +62,7 @@
```r
library(RKorAPClient)
library(knitr)
-KorAPConnection(verbose = TRUE) %>% auth() %>%
+KorAPConnection(verbose = TRUE) |> auth() |>
collocationAnalysis(
"focus(in [tt/p=NN] {[tt/l=setzen]})",
leftContextSize = 1,
@@ -70,10 +70,10 @@
exactFrequencies = FALSE,
searchHitsSampleLimit = 1000,
topCollocatesLimit = 20
- ) %>%
- mutate(LVC = sprintf("[in %s setzen](%s)", collocate, webUIRequestUrl)) %>%
- select(LVC, logDice, pmi, ll) %>%
- head(10) %>%
+ ) |>
+ mutate(LVC = sprintf("[in %s setzen](%s)", collocate, webUIRequestUrl)) |>
+ select(LVC, logDice, pmi, ll) |>
+ head(10) |>
kable(format="pipe", digits=2)
```
@@ -101,7 +101,7 @@
Authorize your RKorAPClient application via the usual OAuth browser flow *using the default application id* and the `auth` method:
```R
-kco <- KorAPConnection() %>% auth()
+kco <- KorAPConnection() |> auth()
```
#### 2. The old way: Authorize your RKorAPClient application manually
@@ -131,7 +131,7 @@
2. Click on the copy symbol ⎘ behind the ID of your client application.
3. Paste your clipboard content overwriting `<application ID>` in the following example code:
```R
- kco <- KorAPConnection() %>% auth(app_id = "<application ID>")
+ kco <- KorAPConnection() |> auth(app_id = "<application ID>")
```
#### Storing and testing your authorized access
@@ -150,7 +150,7 @@
To use the access token for simple corpus queries, i.e. to make `corpusQuery` return KWIC snippets, the `metadataOnly` parameter must be set to `FALSE`, for example:
```R
-corpusQuery(kco, "Ameisenplage", metadataOnly = FALSE) %>% fetchAll()
+corpusQuery(kco, "Ameisenplage", metadataOnly = FALSE) |> fetchAll()
```
should return KWIC snippets, if you have authorized your application successfully.