♻️💄 simplify KorAPConnection class instantiations to modern syntax
Update all class instantiations from `new("KorAPConnection")` to `KorAPConnection()`.
This is possible with R >= 4.0.
Change-Id: I01131fb32045e084cafbb9e05cd8ba99f8f20f1b
diff --git a/R/KorAPConnection.R b/R/KorAPConnection.R
index 3100cee..0dc1a74 100644
--- a/R/KorAPConnection.R
+++ b/R/KorAPConnection.R
@@ -8,7 +8,7 @@
#' Class KorAPConnection
#'
#' `KorAPConnection` objects represent the connection to a KorAP server.
-#' New `KorAPConnection` objects can be created by `new("KorAPConnection")`.
+#' New `KorAPConnection` objects can be created by `KorAPConnection()`.
#'
#' @import R.cache
#' @import utils
@@ -53,7 +53,7 @@
#' in subsequent queries, initialize your KorAP connection with:
#'
#' ```
-#' kco <- new("KorAPConnection", accessToken="<access token>")
+#' kco <- KorAPConnection(accessToken="<access token>")
#' ```
#'
#' In order to make the API
@@ -65,14 +65,14 @@
#' ```
#'
#' This will store it in your keyring using the
-#' [keyring::keyring-package]. Subsequent new("KorAPConnection") calls will
+#' [keyring::keyring-package]. Subsequent KorAPConnection() calls will
#' then automatically retrieve the token from your keying. To stop using a
#' persisted token, call `clearAccessToken(kco)`. Please note that for
#' DeReKo, authorized queries will behave differently inside and outside the
#' IDS, because of the special license situation. This concerns also cached
#' results which do not take into account from where a request was issued. If
#' you experience problems or unexpected results, please try `kco <-
-#' new("KorAPConnection", cache=FALSE)` or use
+#' KorAPConnection(cache=FALSE)` or use
#' [clearCache()] to clear the cache completely.
#'
#' An alternative to using an access token is to use a browser-based oauth2 workflow
@@ -94,14 +94,14 @@
#' @examples
#' \dontrun{
#'
-#' kcon <- new("KorAPConnection", verbose = TRUE)
+#' kcon <- KorAPConnection(verbose = TRUE)
#' kq <- corpusQuery(kcon, "Ameisenplage")
#' kq <- fetchAll(kq)
#' }
#'
#' \dontrun{
#'
-#' kcon <- new("KorAPConnection", verbose = TRUE, accessToken="e739u6eOzkwADQPdVChxFg")
+#' kcon <- KorAPConnection(verbose = TRUE, accessToken="e739u6eOzkwADQPdVChxFg")
#' kq <- corpusQuery(kcon, "Ameisenplage", metadataOnly=FALSE)
#' kq <- fetchAll(kq)
#' kq@collectedMatches$snippet
@@ -169,10 +169,10 @@
#'
#' @examples
#' \dontrun{
-#' kco <- new("KorAPConnection", accessToken="e739u6eOzkwADQPdVChxFg")
+#' kco <- KorAPConnection(accessToken="e739u6eOzkwADQPdVChxFg")
#' persistAccessToken(kco)
#'
-#' kco <- new("KorAPConnection") %>% auth(app_id="<my application id>") %>% persistAccessToken()
+#' kco <- KorAPConnection() %>% auth(app_id="<my application id>") %>% persistAccessToken()
#' }
#'
#' @seealso [clearAccessToken()], [auth()]
@@ -202,7 +202,7 @@
#' @examples
#'
#' \dontrun{
-#' kco <- new("KorAPConnection")
+#' kco <- KorAPConnection()
#' kco <- clearAccessToken(kco)
#' }
#'
@@ -242,7 +242,7 @@
#' @importFrom httr2 oauth_client oauth_flow_auth_code
#' @examples
#' \dontrun{
-#' kco <- new("KorAPConnection", verbose = TRUE) %>% auth()
+#' kco <- KorAPConnection(verbose = TRUE) %>% auth()
#' df <- collocationAnalysis(kco, "focus([marmot/p=ADJA] {Ameisenplage})",
#' leftContextSize=1, rightContextSize=0)
#' }
@@ -467,9 +467,9 @@
##' Funtion KorAPConnection()
##'
-##' Wrappper function for new("KorAPConnection")
+##' Wrappper function for KorAPConnection()
##'
##' @rdname KorAPConnection-constructor
##' @name KorAPConnection-constructor
##' @export
-## XKorAPConnection <- function(...) new("KorAPConnection", ...)
+## XKorAPConnection <- function(...) KorAPConnection(...)
diff --git a/R/KorAPCorpusStats.R b/R/KorAPCorpusStats.R
index 820a248..8639a53 100644
--- a/R/KorAPCorpusStats.R
+++ b/R/KorAPCorpusStats.R
@@ -22,7 +22,7 @@
setGeneric("corpusStats", function(kco, ...) standardGeneric("corpusStats") )
#' Fetch information about a (virtual) corpus
-#' @param kco [KorAPConnection()] object (obtained e.g. from `new("KorAPConnection")`
+#' @param kco [KorAPConnection()] object (obtained e.g. from `KorAPConnection()`
#' @param vc string describing the virtual corpus. An empty string (default) means the whole corpus, as far as it is license-wise accessible.
#' @param verbose logical. If `TRUE`, additional diagnostics are printed.
#' @param as.df return result as data frame instead of as S4 object?
@@ -33,7 +33,7 @@
#'
#' \dontrun{
#'
-#' kco <- new("KorAPConnection")
+#' kco <- KorAPConnection()
#' corpusStats(kco, "pubDate in 2017 & textType=/Zeitung.*/")
#' }
#'
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
index 296efa5..b79b585 100644
--- a/R/KorAPQuery.R
+++ b/R/KorAPQuery.R
@@ -83,7 +83,7 @@
#' @importFrom purrr pmap
#' @importFrom dplyr bind_rows
#'
-#' @param kco [KorAPConnection()] object (obtained e.g. from `new("KorAPConnection")`
+#' @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`.
#' @param vc string describing the virtual corpus in which the query should be performed. An empty string (default) means the whole corpus, as far as it is license-wise accessible.
#' @param KorAPUrl instead of providing the query and vc string parameters, you can also simply copy a KorAP query URL from your browser and use it here (and in `KorAPConnection`) to provide all necessary information for the query.
@@ -113,7 +113,7 @@
#' \dontrun{
#'
#' # Fetch metadata of every query hit for "Ameisenplage" and show a summary
-#' new("KorAPConnection") %>% corpusQuery("Ameisenplage") %>% fetchAll()
+#' KorAPConnection() %>% corpusQuery("Ameisenplage") %>% fetchAll()
#' }
#'
#' \dontrun{
@@ -121,7 +121,7 @@
#' # Use the copy of a KorAP-web-frontend URL for an API query of "Ameise" in a virtual corpus
#' # and show the number of query hits (but don't fetch them).
#'
-#' new("KorAPConnection", verbose = TRUE) %>%
+#' KorAPConnection(verbose = TRUE) %>%
#' corpusQuery(KorAPUrl =
#' "https://korap.ids-mannheim.de/?q=Ameise&cq=pubDate+since+2017&ql=poliqarp")
#' }
@@ -129,7 +129,7 @@
#' \dontrun{
#'
#' # Plot the time/frequency curve of "Ameisenplage"
-#' new("KorAPConnection", verbose=TRUE) %>%
+#' KorAPConnection(verbose=TRUE) %>%
#' { . ->> kco } %>%
#' corpusQuery("Ameisenplage") %>%
#' fetchAll() %>%
@@ -271,7 +271,7 @@
#' @examples
#' \dontrun{
#'
-#' q <- new("KorAPConnection") %>% corpusQuery("Ameisenplage") %>% fetchNext()
+#' q <- KorAPConnection() %>% corpusQuery("Ameisenplage") %>% fetchNext()
#' q@collectedMatches
#' }
#'
@@ -394,7 +394,7 @@
#' @examples
#' \dontrun{
#'
-#' q <- new("KorAPConnection") %>% corpusQuery("Ameisenplage") %>% fetchAll()
+#' q <- KorAPConnection() %>% corpusQuery("Ameisenplage") %>% fetchAll()
#' q@collectedMatches
#' }
#'
@@ -410,7 +410,7 @@
#' @examples
#' \dontrun{
#'
-#' q <- new("KorAPConnection") %>% corpusQuery("Ameisenplage") %>% fetchRest()
+#' q <- KorAPConnection() %>% corpusQuery("Ameisenplage") %>% fetchRest()
#' q@collectedMatches
#' }
#'
@@ -433,11 +433,11 @@
#' @examples
#' \dontrun{
#'
-#' new("KorAPConnection", verbose = TRUE) %>%
+#' KorAPConnection(verbose = TRUE) %>%
#' frequencyQuery(c("Mücke", "Schnake"), paste0("pubDate in ", 2000:2003))
#' }
#'
-#' @param kco [KorAPConnection()] object (obtained e.g. from `new("KorAPConnection")`
+#' @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`.
#' @param conf.level confidence level of the returned confidence interval (passed through [ci()] to [prop.test()]).
#' @param as.alternatives LOGICAL that specifies if the query terms should be treated as alternatives. If `as.alternatives` is TRUE, the sum over all query hits, instead of the respective vc token sizes is used as total for the calculation of relative frequencies.
diff --git a/R/association-scores.R b/R/association-scores.R
index 8c79295..741e69f 100644
--- a/R/association-scores.R
+++ b/R/association-scores.R
@@ -26,7 +26,7 @@
#' @examples
#' \dontrun{
#'
-#' new("KorAPConnection", verbose = TRUE) %>%
+#' KorAPConnection(verbose = TRUE) %>%
#' collocationScoreQuery("Perlen", c("verziertes", "Säue"),
#' scoreFunctions = append(defaultAssociationScoreFunctions(),
#' list(localMI = function(O1, O2, O, N, E, window_size) {
diff --git a/R/ci.R b/R/ci.R
index 19f8615..fcb05e8 100644
--- a/R/ci.R
+++ b/R/ci.R
@@ -25,7 +25,7 @@
#' \dontrun{
#'
#' library(ggplot2)
-#' kco <- new("KorAPConnection", verbose=TRUE)
+#' kco <- KorAPConnection(verbose=TRUE)
#' expand_grid(year=2015:2018, alternatives=c("Hate Speech", "Hatespeech")) %>%
#' bind_cols(corpusQuery(kco, .$alternatives, sprintf("pubDate in %d", .$year))) %>%
#' mutate(total=corpusStats(kco, vc=vc)$tokens) %>%
diff --git a/R/collocationAnalysis.R b/R/collocationAnalysis.R
index b844556..378fd0a 100644
--- a/R/collocationAnalysis.R
+++ b/R/collocationAnalysis.R
@@ -53,7 +53,7 @@
#' \dontrun{
#'
#' # Find top collocates of "Packung" inside and outside the sports domain.
-#' new("KorAPConnection", verbose = TRUE) %>%
+#' KorAPConnection(verbose = TRUE) %>%
#' collocationAnalysis("Packung", vc=c("textClass=sport", "textClass!=sport"),
#' 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.
-#' new("KorAPConnection", verbose = TRUE) %>%
+#' KorAPConnection(verbose = TRUE) %>%
#' collocationAnalysis("focus(in [tt/p=NN] {[tt/l=setzen]})",
#' leftContextSize=1, rightContextSize=0, exactFrequencies=FALSE, topCollocatesLimit=20)
#' }
diff --git a/R/collocationScoreQuery.R b/R/collocationScoreQuery.R
index f9c56fc..6ac1a98 100644
--- a/R/collocationScoreQuery.R
+++ b/R/collocationScoreQuery.R
@@ -12,7 +12,7 @@
#' Computes various collocation association scores
#' based on [frequencyQuery()]s for a target word and a collocate.
#'
-#' @param kco [KorAPConnection()] object (obtained e.g. from `new("KorAPConnection")`
+#' @param kco [KorAPConnection()] object (obtained e.g. from `KorAPConnection()`
#' @param node target word
#' @param collocate collocate of target word
#' @param vc string describing the virtual corpus in which the query should be performed. An empty string (default) means the whole corpus, as far as it is license-wise accessible.
@@ -33,13 +33,13 @@
#' @examples
#' \dontrun{
#'
-#' new("KorAPConnection", verbose = TRUE) %>%
+#' KorAPConnection(verbose = TRUE) %>%
#' collocationScoreQuery("Grund", "triftiger")
#' }
#'
#' \dontrun{
#'
-#' new("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,7 +48,7 @@
#'
#' library(highcharter)
#' library(tidyr)
-#' new("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") %>%
diff --git a/R/hc_add_onclick_korap_search.R b/R/hc_add_onclick_korap_search.R
index 710c1cb..7826ec1 100644
--- a/R/hc_add_onclick_korap_search.R
+++ b/R/hc_add_onclick_korap_search.R
@@ -20,7 +20,7 @@
#' library(highcharter)
#' library(tidyr)
#'
-#' new("KorAPConnection", verbose = TRUE) %>%
+#' KorAPConnection(verbose = TRUE) %>%
#' collocationScoreQuery("Team", "agil", vc = paste("pubDate in", c(2014:2018)),
#' lemmatizeNodeQuery = TRUE, lemmatizeCollocateQuery = TRUE) %>%
#' pivot_longer(c("O", "E")) %>%
diff --git a/R/hc_freq_by_year_ci.R b/R/hc_freq_by_year_ci.R
index f61b87e..a36154f 100644
--- a/R/hc_freq_by_year_ci.R
+++ b/R/hc_freq_by_year_ci.R
@@ -25,14 +25,14 @@
#'
#' year <- c(1990:2018)
#' alternatives <- c("macht []{0,3} Sinn", "ergibt []{0,3} Sinn")
-#' new("KorAPConnection", verbose = TRUE) %>%
+#' KorAPConnection(verbose = TRUE) %>%
#' frequencyQuery(query = alternatives,
#' vc = paste("textType = /Zeit.*/ & pubDate in", year),
#' as.alternatives = TRUE) %>%
#' hc_freq_by_year_ci(as.alternatives = TRUE)
#'
#'
-#' kco <- new("KorAPConnection", verbose = TRUE)
+#' kco <- KorAPConnection(verbose = TRUE)
#' expand_grid(
#' condition = c("textDomain = /Wirtschaft.*/", "textDomain != /Wirtschaft.*/"),
#' year = (2005:2011)
diff --git a/R/misc.R b/R/misc.R
index 9abbe07..ac70f47 100644
--- a/R/misc.R
+++ b/R/misc.R
@@ -23,7 +23,7 @@
#' @examples
#' \dontrun{
#'
-#' new("KorAPConnection") %>% frequencyQuery("Test", paste0("pubDate in ", 2000:2002)) %>% ipm()
+#' KorAPConnection() %>% frequencyQuery("Test", paste0("pubDate in ", 2000:2002)) %>% ipm()
#' }
ipm <- function(df) {
df %>%
@@ -46,7 +46,7 @@
#' @examples
#' \dontrun{
#'
-#' new("KorAPConnection") %>%
+#' KorAPConnection() %>%
#' frequencyQuery(c("Tollpatsch", "Tolpatsch"),
#' vc=paste0("pubDate in ", 2000:2002),
#' as.alternatives = TRUE) %>%
@@ -113,7 +113,7 @@
#' @examples
#' \dontrun{
#' library(ggplot2)
-#' kco <- new("KorAPConnection", verbose=TRUE)
+#' kco <- KorAPConnection(verbose=TRUE)
#'
#' expand_grid(condition = c("textDomain = /Wirtschaft.*/", "textDomain != /Wirtschaft.*/"),
#' year = (2005:2011)) %>%
diff --git a/R/textMetadata.R b/R/textMetadata.R
index 2e5372f..a6f00ce 100644
--- a/R/textMetadata.R
+++ b/R/textMetadata.R
@@ -9,7 +9,7 @@
#' (see [Kustvakt Wiki](https://github.com/KorAP/Kustvakt/wiki/Service:-Metadata-Retrieval)).
#'
#'
-#' @param kco [KorAPConnection()] object (obtained e.g. from `new("KorAPConnection")`)
+#' @param kco [KorAPConnection()] object (obtained e.g. from `KorAPConnection()`)
#' @param textSigle unique text id (concatenation of corpus, document and text ids, separated by `/`, e.g. ) or vector thereof
#' @param verbose logical. If `TRUE`, additional diagnostics are printed. Defaults to `kco@verbose`.
#'
@@ -23,7 +23,7 @@
#'
#' @examples
#' \dontrun{
-#' new("KorAPConnection") %>% textMetadata(c("WUD17/A97/08542", "WUD17/B96/57558", "WUD17/A97/08541"))
+#' KorAPConnection() %>% textMetadata(c("WUD17/A97/08542", "WUD17/B96/57558", "WUD17/A97/08541"))
#' }
#'
#' @export