title: R: import pdf and create TermDocumentMatrix with files names as id
body: <p>I'm importing pdf to R in order to do some text analysis. I have a number of pdf files whose names are their publication year (one publication per year). </p>
  
  <p>I would like to create a TermDocumentMatrix after importing them for which the first term "docs" (ie the first column of the tdm) takes the year of the publication rather than the number of the document. Indeed, at the moment the tdm assigns them numbers (1, 2, 3 etc...) when I create it. </p>
  
  <p>Any ideas on how to do it? My code is below. </p>
  
  <p>Thanks!</p>
  
  <pre><code>#creates the list of pdf files to be picked up (from the working directory)
  files &lt;- list.files(pattern = "pdf$")
  
  #read the pdf files from the list (number of pages in brackets in front)
  new_files &lt;- sapply(files, pdf_text)
  
  #create corpus
  new_corp &lt;- Corpus(VectorSource(new_files))
  
  IMF_tdm &lt;- TermDocumentMatrix(new_corp, control = list(removePunctuation = TRUE,
                                                           stopwords = TRUE,
                                                           tolower = TRUE,
                                                           stemming = TRUE,
                                                           removeNumbers = TRUE,
                                                           bounds = list(global =c(2, Inf)))) 
  </code></pre>