I am detecting words with stringr and regex and noticed that I am missing several items because the words are split when there’s a linebreak.
Strikingly, the symbol breaking the word is not visible when I print the cell’s content or look at it in RStudio’s data viewer. I can only see that words were split when copying-pasting the content of e.g. the dataframe’s cell into the console. There is a little dot separating the word, e.g. Schallenberg is represented as Schallen[dot]berg (a little dot, vertically in the middle of the line);
I assume that the invisibility of the symbols splitting the words has something to do with the text’s origin. They were retrieved via rvest. However, even more strikingly when I check the words which contain the symbol on the website, they are not split.
My question: How can I remove these otherwise invisible symbols? They are not removed with stringr::str_squish. Do I have to account for them when already extracting the text from the website? Many thanks!
library(rvest, quietly = T, warn.conflicts = F)
library(tidyverse, quietly = T, warn.conflicts = F)
web_link <- "https://www.parlament.gv.at//PAKT/VHG/XXVII/NRSITZ/NRSITZ_00006/fnameorig_797359.html"
df_txt <- web_link %>%
read_html(., encoding = "latin1") %>%
html_nodes("body > div.WordSection37 > p:nth-child(2) > b:nth-child(2) > span") %>%
html_text2() %>%
enframe(name = NULL,
value="text_raw") %>%
mutate(text_raw=text_raw %>% str_squish %>% str_trim(., "both"))
# There is a dot between Schallen - berg, but it's not visible
print(df_txt$text_raw)
#> [1] "Bundesminister für Europa, Integration und Äußeres Mag. Alexander Schallenberg, LL.M."
str_detect(df_txt$text_raw, "Schallenberg") #false
#> [1] FALSE
Created on 2021-04-08 by the reprex package (v1.0.0)
