You can use tm, ngram and NLP package in RStudio. These packages define various function which will help in sentiment analysis of novel or content in any book.
Sentiment analysis tools use natural language processing (NLP) to analyze online conversations and determine deeper context - positive, negative, neutral. These tools mimic our brains, to a greater or lesser extent, allowing us to monitor the sentiment behind online content.