test_that("limpiar_recode_emojis recodes not removes", {
emojis <- data.frame(
text = c("Hello π World",
"Family: π¨βπ©βπ§βπ¦",
"Coding π¨π½βπ»",
"Flags π³οΈβπ πΊπΈ",
"Weather βοΈ βοΈ βοΈ")
)
expect_true(grepl("π", emojis$text[1]))
expect_true(grepl("π¨βπ©βπ§βπ¦", emojis$text[2]))
recoded <- limpiar_recode_emojis(emojis, text)
expect_true(grepl("waving hand", recoded$text[[1]]))
expect_true(grepl("man.*woman.*girl", recoded$text[[2]]))
})
test_that("limpiar_remove_emojis input validation works", {
df <- data.frame(text = c("Hello π", "World π"))
expect_error(limpiar_remove_emojis("not_a_df", "text"))
expect_error(limpiar_remove_emojis(df, 123))
expect_error(limpiar_remove_emojis(df, "missing_col"))
})
test_that("limpiar_remove_emojis preserves special characters", {
input_df <- tibble::tribble(
~text,
"cafΓ© Ο ΞΌ", # Accents and Greek
"MΓΌnchen ist schΓΆn", # German umlauts
"ΡΡΡΡΠΊΠΈΠΉ ΡΠ·ΡΠΊ", # Russian
"ζΌ’εγ¨γ²γγγͺ", # Chinese and Japanese
"Hello! @ # $ % ^", # Punctuation
"HβO + COβ", # Subscripts
"β β + Γ· Γ β " # Math symbols
)
output_df <- limpiar_remove_emojis(input_df, text)
# check we didn't remove stuff we didn't want to
expect_equal(output_df$text[1], "cafΓ© Ο ΞΌ")
expect_equal(output_df$text[2], "MΓΌnchen ist schΓΆn")
expect_equal(output_df$text[3], "ΡΡΡΡΠΊΠΈΠΉ ΡΠ·ΡΠΊ")
expect_equal(output_df$text[4], "ζΌ’εγ¨γ²γγγͺ")
})
test_that("limpiar_remove_emojis removes all emoji types", {
input_df <- tibble::tribble(
~text,
"Hello π World",
"Family: π¨βπ©βπ§βπ¦",
"Coding π¨π½βπ»",
"Flags π³οΈβπ πΊπΈ",
"Weather βοΈ βοΈ βοΈ"
)
# First verify emojis are present
expect_match(input_df$text[1], "\U{1F44B}") # Wave emoji
expect_match(input_df$text[2], "π¨βπ©βπ§βπ¦") # Family
expect_match(input_df$text[3], "π¨π½βπ»") # Professional with skin tone
expect_match(input_df$text[4], "π³οΈβπ") # Pride flag
expect_match(input_df$text[5], "[βοΈβοΈβοΈ]") # Weather symbols
# Remove emojis
output_df <- limpiar_remove_emojis(input_df, text)
# Verify emojis are gone
expect_false(any(grepl("\U{1F44B}", output_df$text[1])))
expect_false(any(grepl("π¨βπ©βπ§βπ¦", output_df$text[2])))
expect_false(any(grepl("π¨π½βπ»", output_df$text[3])))
expect_false(any(grepl("π³οΈβπ", output_df$text[4])))
expect_false(any(grepl("[βοΈβοΈβοΈ]", output_df$text[5])))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.