diff --git a/NEWS.md b/NEWS.md index b5b6eaa5..2b24c91c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,7 @@ values. Warning issued now. available for s_attribute defined by `mw`. * `decode()` to `AnnotatedPlainTextDocument` failed if a document contains only one token. Fixed #285. +* `decode()` failed if nested s-attribute does not occur. Fixed #284. # polmineR v0.8.9 diff --git a/R/decode.R b/R/decode.R index e976f9c8..4daab64c 100644 --- a/R/decode.R +++ b/R/decode.R @@ -470,8 +470,16 @@ setMethod("decode", "slice", function(.Object, to = c("data.table", "Annotation" registry = .Object@registry_dir, region_matrix = .Object@cpos ) - strucs <- RcppCWB::ranges_to_cpos(struc_matrix) - if (length(strucs) == 0L) next + strucs <- suppressWarnings(RcppCWB::ranges_to_cpos(struc_matrix)) + if (length(strucs) == 0L){ + if (decode){ + y[, (s_attributes[i]) := rep(NA_character_, times = nrow(y))] + } else { + y[, (s_attributes[i]) := rep(NA_integer_, times = nrow(y))] + } + + next + } regions <- RcppCWB::get_region_matrix( corpus = .Object@corpus,