title: Extracting original text from quanteda dfm for use in stm
body: <p>I used both quanteda and stm packages. The first one helps me to
  preprocess data, and I did topic modeling with the second packages.</p>
  
  <p>When I try to use findthoughts function, I find following errors:</p>
  
  <pre><code>Error in if (!is.null(texts) &amp;&amp; length(texts) != nrow(theta)) stop("Number of       
  provided texts and number of documents modeled do not match") : 
  missing value where TRUE/FALSE needed
  </code></pre>
  
  <p>I think this is because I removed the empty lines from my original text by
  using the following command </p>
  
  <pre><code>text &lt;- rs[complete.cases(data), ]
  </code></pre>
  
  <p>and using sparsity=0.99, which also remove some less used words.</p>
  
  <p>So the original text and new text does not match.
  However, I do not know how I can reach the new text file after dfm 
  function?</p>
  
  <p>In the reproducible example (not my own data), if we assume there are missing values in the text,
  can you help me to get the text after dfm function.</p>
  
  <pre><code>library(stm)
  library(quanteda)
  
  data &lt;- corpus(gadarian, text_field = 'open.ended.response')
  docvars(data)$text &lt;- texts(data)
  data &lt;- dfm(data, stem = TRUE, remove = stopwords('english'),
         remove_punct = TRUE) %&gt;% dfm_trim(min_count = 2)
  out &lt;- convert(data, to = 'stm')
  
  gadarian_3 &lt;- stm(documents = out$documents,
               vocab = out$vocab,
               data = out$meta,
               prevalence = ~ treatment + s(pid_rep),
               K = 10, verbose = FALSE)
  
  outputFit &lt;-  gadarian_3$runout[[1]]
  thoughts1&lt;-findThoughts(gadarian_3, texts=textdata , n=10, topics=1)$docs[[1]]
  </code></pre>