Skip to content

Instantly share code, notes, and snippets.

@Robinlovelace
Last active July 8, 2018 23:33
Show Gist options
  • Save Robinlovelace/f32e685b939b54db2d15c1accacdb119 to your computer and use it in GitHub Desktop.
Save Robinlovelace/f32e685b939b54db2d15c1accacdb119 to your computer and use it in GitHub Desktop.
``` r
pkgs = c("stringr", "emojifont")
if(any(!pkgs %in% installed.packages())) {
install.packages(pkgs)
}
story_original = "🍞🍻🐒😱πŸ₯πŸ˜·πŸ’Šβž‘πŸ₯›β˜•πŸ’ͺπŸ…πŸš²πŸ»"
# something funny with 9th char
char_broken = stringr::str_sub(story_original, start = 9, end = 9)
emojifont::search_emoji("bottle")
#> [1] "baby_bottle"
char_fixed = emojifont::emoji("baby_bottle")
story = stringr::str_replace(story_original, pattern = char_broken, replacement = char_fixed)
story
#> [1] "🍞🍻🐒😱πŸ₯πŸ˜·πŸ’Šβž‘πŸΌβ˜•πŸ’ͺπŸ…πŸš²πŸ»"
stringr::str_sub(story, start = (nchar(story) - 3))
#> [1] "πŸ’ͺπŸ…πŸš²πŸ»"
stringr::str_sub(story, start = (nchar(story) - 2))
#> [1] "πŸ…πŸš²πŸ»"
story_vec = stringr::str_split(story, "", simplify = TRUE)
story_vec[-(1:(length(story_vec) - 3))]
#> [1] "πŸ…" "🚲" "🍻"
# print result (commented):
# reprex::reprex(si = TRUE, x = {
# pkgs = c("stringr", "emojifont")
# if(any(!pkgs %in% installed.packages())) {
# install.packages(pkgs)
# }
# story_original = "🍞🍻🐒😱πŸ₯πŸ˜·πŸ’Šβž‘πŸ₯›β˜•πŸ’ͺπŸ…πŸš²πŸ»"
# # something funny with 9th char
# char_broken = stringr::str_sub(story_original, start = 9, end = 9)
# emojifont::search_emoji("bottle")
# char_fixed = emojifont::emoji("baby_bottle")
# story = stringr::str_replace(story_original, pattern = char_broken, replacement = char_fixed)
# story
# stringr::str_sub(story, start = (nchar(story) - 3))
# stringr::str_sub(story, start = (nchar(story) - 2))
# story_vec = stringr::str_split(story, "", simplify = TRUE)
# story_vec[-(1:(length(story_vec) - 3))]
# })
"bye!"
#> [1] "bye!"
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment