dplyr 中的 stringi 函数

stringi functions within dplyr

我想修改另一个post()中的方法,检查一个unicode字符串是否对应一个emoji...但是我显然还没有完全掌握如何使用stringi 正确。

代码的第一部分是对链接 post 的简化,并且按预期工作;第一个和最后一个条目被替换:

a <- c("\U0001f600",       "\U0001f603",       "\U0001f604")
b <- c("grinning face", "grinning face with big eyes", "grinning face with smiling eyes" )

v <- data.frame(lemma = c("\U0001f600",  "\U0001f3fb", "hello", "asdfasdlkasdfkd", "\U0001f604"), stringsAsFactors = FALSE)
v %>% mutate(is_emoji = stri_replace_all_regex(lemma,
                       pattern = a,
                       replacement = b,
                       vectorize_all=FALSE))

但是我对 return 布尔值的尝试没有;除了警告消息 "longer object length is not a multiple of shorter object length",我没有使用以下代码获得等于 TRUE 的最后一个值:

v %>% mutate(is_emoji = stri_detect_regex(lemma, pattern = a))

我尝试了无数其他变体,但都没有成功。

pastecollapse='|'

结合使用
v %>% mutate(is_emoji = stri_detect_regex(lemma, pattern = paste(a, collapse = '|')))