Skip to content

Commit bd65625

Browse files
author
Youzhi Yu
committed
added examples
1 parent 074c38c commit bd65625

File tree

10 files changed

+135
-9
lines changed

10 files changed

+135
-9
lines changed

R/emoji-categorize.R

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,31 @@ emoji_category_add <- function(emoji_unicodes, emoji_category, tweet_tbl, tweet_
2222
#' @return A filtered dataframe with the presence of Emoji only, and with an
2323
#' extra column \code{.emoji_category}.
2424
#' @export
25-
#'
25+
#' @examples
26+
#' library(dplyr)
27+
#' data.frame(tweets = c("I love tidyverse \U0001f600\U0001f603\U0001f603",
28+
#' "R is my language! \U0001f601\U0001f606\U0001f605",
29+
#' "This Tweet does not have Emoji!",
30+
#' "Wearing a mask\U0001f637\U0001f637\U0001f637.",
31+
#' "Emoji does not appear in all Tweets",
32+
#' "A flag \U0001f600\U0001f3c1")) %>%
33+
#' emoji_categorize(tweets)
2634

2735

2836
emoji_categorize <- function(tweet_tbl, tweet_text) {
2937

30-
purrr::map2_dfr(tidyEmoji::category_unicode_crosswalk$unicodes,
31-
tidyEmoji::category_unicode_crosswalk$category,
32-
emoji_category_add,
33-
tweet_tbl,
34-
{{ tweet_text }}) %>%
38+
emoji_long <- purrr::map2_dfr(tidyEmoji::category_unicode_crosswalk$unicodes,
39+
tidyEmoji::category_unicode_crosswalk$category,
40+
emoji_category_add,
41+
tweet_tbl,
42+
{{ tweet_text }})
43+
44+
emoji_category_vector <- unique(emoji_long$.emoji_category)
45+
46+
emoji_long %>%
3547
tidyr::pivot_wider(names_from = .emoji_category,
3648
values_from = .emoji_category) %>%
37-
tidyr::unite(".emoji_category", c("Smileys & Emotion": "Flags"), sep = "|", na.rm = T)
49+
tidyr::unite(".emoji_category", emoji_category_vector, sep = "|", na.rm = T)
3850

3951

4052
}

R/emoji-extraction.R

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@
1212
#' @import tidyr
1313
#' @return A summary tibble with the original row number and Emoji count.
1414
#' @export
15+
#' @examples
16+
#' library(dplyr)
17+
#' data.frame(tweets = c("I love tidyverse \U0001f600\U0001f603\U0001f603",
18+
#' "R is my language! \U0001f601\U0001f606\U0001f605",
19+
#' "This Tweet does not have Emoji!",
20+
#' "Wearing a mask\U0001f637\U0001f637\U0001f637.",
21+
#' "Emoji does not appear in all Tweets",
22+
#' "A flag \U0001f600\U0001f3c1")) %>%
23+
#' emoji_extract_unnest(tweets)
1524
#'
25+
26+
1627
emoji_extract_unnest <- function(tweet_tbl, tweet_text){
1728
tweet_tbl %>%
1829
tidyEmoji::emoji_extract_nest({{ tweet_text }}) %>%
@@ -44,7 +55,18 @@ emoji_extract_unnest <- function(tweet_tbl, tweet_text){
4455
#' @return The original dataframe/tibble with an extra column collumn called
4556
#' \code{.emoji_unicode}.
4657
#' @export
47-
#'
58+
#' @examples
59+
#' library(dplyr)
60+
#' data.frame(tweets = c("I love tidyverse \U0001f600\U0001f603\U0001f603",
61+
#' "R is my language! \U0001f601\U0001f606\U0001f605",
62+
#' "This Tweet does not have Emoji!",
63+
#' "Wearing a mask\U0001f637\U0001f637\U0001f637.",
64+
#' "Emoji does not appear in all Tweets",
65+
#' "A flag \U0001f600\U0001f3c1")) %>%
66+
#' emoji_extract_nest(tweets)
67+
68+
69+
4870
emoji_extract_nest <- function(tweet_tbl, tweet_text){
4971
tweet_tbl %>%
5072
dplyr::mutate(.emoji_unicode = stringr::str_extract_all({{ tweet_text }}, emoji::emojis %>%

R/emoji-summary.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,19 @@
1818
#' @import stringr
1919
#' @import tibble
2020
#' @export
21+
#' @examples
22+
#' library(dplyr)
23+
#' data.frame(tweets = c("I love tidyverse \U0001f600\U0001f603\U0001f603",
24+
#' "R is my language! \U0001f601\U0001f606\U0001f605",
25+
#' "This Tweet does not have Emoji!",
26+
#' "Wearing a mask\U0001f637\U0001f637\U0001f637.",
27+
#' "Emoji does not appear in all Tweets",
28+
#' "A flag \U0001f600\U0001f3c1")) %>%
29+
#' emoji_summary(tweets)
2130
#'
2231

2332

33+
2434
emoji_summary <- function(tweet_tbl, tweet_text){
2535

2636
num_tweets <- dim(tweet_tbl)[1]
@@ -53,6 +63,17 @@ emoji_summary <- function(tweet_tbl, tweet_text){
5363
#'
5464
#' @return A dataframe/tibble containing only text with at least one Emoji
5565
#' @export
66+
#' @examples
67+
#' library(dplyr)
68+
#' data.frame(tweets = c("I love tidyverse \U0001f600\U0001f603\U0001f603",
69+
#' "R is my language! \U0001f601\U0001f606\U0001f605",
70+
#' "This Tweet does not have Emoji!",
71+
#' "Wearing a mask\U0001f637\U0001f637\U0001f637.",
72+
#' "Emoji does not appear in all Tweets",
73+
#' "A flag \U0001f600\U0001f3c1")) %>%
74+
#' emoji_tweets(tweets)
75+
#'
76+
5677

5778
emoji_tweets <- function(tweet_tbl, tweet_text){
5879

R/top-n-emojis.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@
1919
#' @import purrr
2020
#' @import dplyr
2121
#' @export
22-
#'
22+
#' @examples
23+
#' library(dplyr)
24+
#' data.frame(tweets = c("I love tidyverse \U0001f600\U0001f603\U0001f603",
25+
#' "R is my language! \U0001f601\U0001f606\U0001f605",
26+
#' "This Tweet does not have Emoji!",
27+
#' "Wearing a mask\U0001f637\U0001f637\U0001f637.",
28+
#' "Emoji does not appear in all Tweets",
29+
#' "A flag \U0001f600\U0001f3c1")) %>%
30+
#' top_n_emojis(tweets, n = 2)
2331

2432

2533
top_n_emojis <- function(tweet_tbl, tweet_text, n = 20, duplicated_unicode = "no"){

man/emoji_categorize.Rd

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/emoji_extract_nest.Rd

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/emoji_extract_unnest.Rd

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/emoji_summary.Rd

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/emoji_tweets.Rd

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/top_n_emojis.Rd

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)