EmilHvitfeldt / smltar

Manuscript of the book "Supervised Machine Learning for Text Analysis in R" by Emil Hvitfeldt and Julia Silge

Home Page:https://smltar.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chapter 4 Stemming Code Error

gunnergalactico opened this issue · comments

Thanks for writing the book, as I was working through the chapter I noticed that the ungroup function has missing brackets.

code 1

tidy_by_lang %>% inner_join(stopword_df) %>% mutate(data = map2( data, two_letter, ~ anti_join(.x, get_stopwords(language = .y))) ) %>% unnest(data) %>% mutate(stem = wordStem(word, language = language)) %>% group_by(language) %>% count(stem) %>% top_n(20, n) %>% ungroup %>% ggplot(aes(n, fct_reorder(stem, n), fill = language)) + geom_col(show.legend = FALSE) + facet_wrap(~language, scales = "free_y", ncol = 2) + labs(x = "Frequency", y = NULL)

code 2

stemming %>% gather(Type, Result, Remove S:Porter stemming) %>% mutate(Type = fct_inorder(Type)) %>% count(Type, Result) %>% group_by(Type) %>% top_n(20, n) %>% ungroup %>% ggplot(aes(fct_reorder(Result, n), n, fill = Type)) + geom_col(show.legend = FALSE) + facet_wrap(~Type, scales = "free_y") + coord_flip() + labs(x = NULL, y = "Frequency")

Thanks.

Thanks so much for this report @gunnergalactico! It is not an error per se because this function works with/without parentheses in a pipe, but it is a code style issue that we would like to address. I made the change in the .Rmd that generates Ch 4 but you won't see that reflected on the website until we render the book again.