From 176298e3c3f0e07925e95b53b8c1a26a0a5733ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Bl=C3=A4tte?= Date: Fri, 16 Feb 2024 18:19:27 +0100 Subject: [PATCH] no ranges_to_cpos() warning in decode(to = "AnnotatedPlainTextDocument") --- DESCRIPTION | 4 ++-- NEWS.md | 4 +++- R/decode.R | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 59d401a5..423d2493 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: polmineR Type: Package Title: Verbs and Nouns for Corpus Analysis -Version: 0.8.9.9001 -Date: 2023-11-04 +Version: 0.8.9.9002 +Date: 2024-02-16 Authors@R: c( person("Andreas", "Blaette", role = c("aut", "cre"), email = "andreas.blaette@uni-due.de", comment = c(ORCID = "0000-0001-8970-8010")), person("Christoph", "Leonhardt", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index ab462543..ee494355 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# polmineR v0.8.9.9001 +# polmineR v0.8.9.9001-9002 * S4 class has new slot 'match' for decoded matches for query. * Method `ranges()` adds decoded token stream of query matches to 'ranges' @@ -7,6 +7,8 @@ object (slot "match") that is returned #277. 'query' or by 'match' #278. * `subset()` for subcorpus objects issued ERROR if s-attribute did not have values. Warning issued now. +* No warning for `decode(to = "AnnotatedPlainTextDocument")` of no regions +available for s_attribute defined by `mw`. # polmineR v0.8.9 diff --git a/R/decode.R b/R/decode.R index c3f6cc00..3c52490e 100644 --- a/R/decode.R +++ b/R/decode.R @@ -125,6 +125,11 @@ as.AnnotatedPlainTextDocument <- function(x, p_attributes = NULL, s_attributes = region_matrix = x@cpos, s_attribute = s_attr ) + # missing regions for s_attr within regions result in NAs + drop <- which(apply(struc_matrix, 1, function(row) any(is.na(row)))) + if (length(drop) > 0L) struc_matrix <- struc_matrix[-drop,] + if (nrow(struc_matrix) == 0L) return(NULL) + strucs <- ranges_to_cpos(struc_matrix) strucs_min <- unique(strucs[strucs >= 0L]) if (length(strucs_min) == 0L) return(NULL)