CA: catch case when no examples are found
Change-Id: Icd241709d2701a37771b4f2dbf9f3dff754e1a30
diff --git a/R/collocationAnalysis.R b/R/collocationAnalysis.R
index 52a0e33..6033ca9 100644
--- a/R/collocationAnalysis.R
+++ b/R/collocationAnalysis.R
@@ -370,13 +370,17 @@
for (i in seq_along(query)) {
q <- corpusQuery(kco, paste0("(", query[i], ")"), vc = vc[i], metadataOnly = FALSE)
- q <- fetchNext(q, maxFetch=50, randomizePageOrder=F)
- example <- as.character((q@collectedMatches)$snippet[1])
- out[i] <- if(matchOnly) {
+ if (q@totalResults > 0) {
+ q <- fetchNext(q, maxFetch=50, randomizePageOrder=F)
+ example <- as.character((q@collectedMatches)$snippet[1])
+ out[i] <- if(matchOnly) {
gsub('.*<mark>(.+)</mark>.*', '\\1', example)
} else {
stringr::str_replace(example, '<[^>]*>', '')
}
+ } else {
+ out[i] = ""
+ }
}
out
}