dgrtwo / tidy-text-mining

Manuscript of the book "Tidy Text Mining with R" by Julia Silge and David Robinson
http://tidytextmining.com
Other
1.31k stars 803 forks source link

Avoid adding columns with other functions #86

Closed arencambre closed 3 years ago

arencambre commented 3 years ago

There are a few cases in the textbook where you are adding columns with other functions. For example, in chapter 2 is this code snippet:

jane_austen_sentiment <- tidy_books %>%
  inner_join(get_sentiments("bing")) %>%
  count(book, index = linenumber %/% 80, sentiment) %>%
  spread(sentiment, n, fill = 0) %>%
  mutate(sentiment = positive - negative)

I'd prefer that a separate mutate command be used to create the index column. While what you are doing is fully correct, I suspect this book is used by beginners, so it would help to have the dplyr concepts separated into their own lines.

If you agree, I'd be happy to create a pull request to address this.

juliasilge commented 3 years ago

Thanks for your thoughts here @arencambre! This is one of the things we want to be able to demonstrate for folks in practical use.