过滤除某些特定单词外所有字符长度相同的单词

Filter all words with the same character length except some specific words

我知道我可以按照以下顺序删除所有只有 2 个字符的单词项:

data %>% filter(str_length(word) != 2)

在我的案例中,我想过滤所有包含 2 个字符的项目,但像“EU”这样的特定词应该仍在小标题中。是否可以对上面的顺序定义一些期望?

假设您要过滤除“EU”和“UE”之外的所有两个字母的单词:

test <- tibble(word=c("Word", "Another word", "Wo", "Wa", "EU","UE"))

test

# A tibble: 6 x 1
  word        
  <chr>       
1 Word        
2 Another word
3 Wo          
4 Wa          
5 EU          
6 UE   

test %>% filter(ifelse(str_length(word)==2 & !grepl("EU|UE", word), FALSE, TRUE))

 A tibble: 4 x 1
  word        
  <chr>       
1 Word        
2 Another word
3 EU          
4 UE