Last active
July 8, 2018 23:33
-
-
Save Robinlovelace/f32e685b939b54db2d15c1accacdb119 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` 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