title: Get all of the nouns in a book (.txt file) in R and make a frequency table and wordcloud
body: <p>I am trying to find all of the nouns in a text file. Originally I converted a .epub to a .pdf file. Then I converted the .pdf to a .txt file successfully and I removed half of the text since I only need to find the nouns from the last half of the book. I want to do this so I can find the frequency of the nouns and then identify them for finals. </p>
  
  <p>I can do the frequency tables normally with the original text files without any transformations and make a wordcloud etc but I cannot seem to filter only the nouns. Any ideas? </p>
  
  <pre><code>cname &lt;- file.path(".","Desktop", "egypt", "pdf")
  mytxtfiles &lt;- list.files(path = cname, pattern = "txt",  full.names = TRUE) 
  
  #nouns2 and nouns doesnt seem to work :O -Ive tried both ways-
  nouns2 &lt;- regmatches(mytxtfiles, gregexpr("^([A-Z][a-z]+)+$", mytxtfiles, perl=TRUE))
  nouns &lt;- lapply(mytxtfiles, function(i) {
  j &lt;- paste0(scan(i, what = character()), collapse = " ")
  regmatches(j, gregexpr("^([A-Z][a-z]+)+$", j, perl=TRUE))})
  
  #transformation if nouns do not work
  docs &lt;- tm_map(docs[1], removeWords, stopwords("english"))
  
  #working wordcloud and freq data 
  dtm &lt;- DocumentTermMatrix(docs)
  findFreqTerms(dtm, lowfreq=100)
  findAssocs(dtm, "data", corlimit=0.6)
  freq &lt;- sort(colSums(as.matrix(dtm)), decreasing=TRUE)
  wf &lt;- data.frame(word=names(freq), freq=freq)
  p &lt;- ggplot(subset(wf, freq &gt;500), aes(word, freq))
  p &lt;-p + geom_bar(stat ="identity")
  p &lt;- p + theme(axis.text.x=element_text(angle=45, hjust=1))             
  library(wordcloud)
  wordcloud(names(freq),freq,min.freq=100, colors=brewer.pal(6,"Dark2"))
  </code></pre>
  
  <p>I have tried nouns2 and nouns but they return something like:</p>
  
  <pre><code>nouns2
  [[1]]
  character(0)
  [[2]]
  character(0)
  [[3]]
  character(0)
  </code></pre>