From c32c9e5ad373b20d93fea87fddf045a437153574 Mon Sep 17 00:00:00 2001 From: Erik de Vries Date: Sun, 30 Dec 2018 19:34:48 +0100 Subject: [PATCH] ud_update: fix to deal with non-existing column names --- R/ud_update.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/R/ud_update.R b/R/ud_update.R index 1625602..602101b 100644 --- a/R/ud_update.R +++ b/R/ud_update.R @@ -20,6 +20,16 @@ # } ud_update <- function(out, localhost = T, udmodel, es_super = .rs.askForPassword("ElasticSearch WRITE"), cores = detectCores(), ver) { + fncols <- function(data, cname) { + add <-cname[!cname%in%names(data)] + + if(length(add)!=0) data[add] <- NA + data + } + + out <- fncols(out, c('_source.text', '_source.title','_source.teaser','_source.subtitle','_source.preteaser')) + out <- replace(out, out=="NULL", NA) + ### Use correct interpunction, by inserting a '. ' at the end of every text field, then removing any duplicate occurences out <- out %>% mutate(`_source.title` = str_replace_na(`_source.title`, replacement = '')) %>%