Skip to content

Instantly share code, notes, and snippets.

@krlmlr
Created October 25, 2023 04:05
Show Gist options
  • Save krlmlr/0abe8059d99427838aee06c540bc54c5 to your computer and use it in GitHub Desktop.
Save krlmlr/0abe8059d99427838aee06c540bc54c5 to your computer and use it in GitHub Desktop.
facepalm <- "\U1F926"
fitzpatrick_3 <- "\U1F3FC"
zero_width_joiner <- "\U200D"
male <- "\U2642"
my_facepalm <- paste0(facepalm, fitzpatrick_3, zero_width_joiner, male)
my_facepalm
#> [1] "🤦🏼‍♂"
# 😱
nchar(my_facepalm)
#> [1] 4
nchar(my_facepalm, type = "width")
#> [1] 5
data.frame(my_facepalm, a = 1)
#> my_facepalm a
#> 1 🤦🏼‍♂ 1
# ✅
utf8::utf8_width(my_facepalm)
#> [1] 2
tibble::tibble(my_facepalm, a = 1)
#> # A tibble: 1 × 2
#> my_facepalm a
#> <chr> <dbl>
#> 1 🤦🏼‍♂ 1
library(stringi)
stri_count_boundaries(my_facepalm, opts_brkiter = stri_opts_brkiter("character"))
#> [1] 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment