title: Numbers of columns of arguments do not match
body: <p>I am using this <a href="https://www.kaggle.com/rtatman/tutorial-sentiment-analysis-in-r" rel="noreferrer">example</a> to conduct sentiment analysis of a collection of txt documents in R. The code is:</p>
  
  <pre><code>library(tm)
  library(tidyverse)
  library(tidytext)
  library(glue)
  library(stringr)
  library(dplyr)
  library(wordcloud)
  require(reshape2)
  
  files &lt;- list.files(inputdir,pattern="*.txt")
  
  GetNrcSentiment &lt;- function(file){
  
      fileName &lt;- glue(inputdir, file, sep = "")
      fileName &lt;- trimws(fileName)
      fileText &lt;- glue(read_file(fileName))
      fileText &lt;- gsub("\\$", "", fileText) 
  
      tokens &lt;- data_frame(text = fileText) %&gt;% unnest_tokens(word, text)
  
      # get the sentiment from the first text: 
      sentiment &lt;- tokens %&gt;%
          inner_join(get_sentiments("nrc")) %&gt;% # pull out only sentiment words
          count(sentiment) %&gt;% # count the # of positive &amp; negative words
          spread(sentiment, n, fill = 0) %&gt;% # made data wide rather than narrow
          mutate(sentiment = positive - negative) %&gt;% # positive - negative
          mutate(file = file) %&gt;% # add the name of our file
          mutate(year = as.numeric(str_match(file, "\\d{4}"))) %&gt;% # add the year
          mutate(city = str_match(file, "(.*?).2")[2]) 
  
      return(sentiment)
  }
  </code></pre>
  
  <p>The .txt files are stored in <code>inputdir</code>and have names <code>AB-City.0000</code>, where AB is an abbreviation of  a country, City is a city name and 0000 is year (ranges from 2000 to 2017).</p>
  
  <p>The function works for a single file as expected, i.e. <code>GetNrcSentiment(files[1])</code> gives me a tibble with proper counts per sentiment. However, when i try to run it for the whole set, i.e.</p>
  
  <pre><code>nrc_sentiments  &lt;- data_frame()
  
  for(i in files){
      nrc_sentiments &lt;- rbind(nrc_sentiments, GetNrcSentiment(i))
  }
  </code></pre>
  
  <p>I get the following error message:</p>
  
  <pre><code>Joining, by = "word"
  Error in rbind(deparse.level, ...) : 
    numbers of columns of arguments do not match
  </code></pre>
  
  <p>The exact same code works well with longer documents, but gives an error when dealing with shorter texts. It seems that not all sentiments are found in small documents and as a result the number of columns vary for each document, which might lead to this error, but I am not sure. I would appreciate any advice on how to fix the problem. If a sentiment is not found, I would want the entry to be equal to zero (if it is the cause of my problem).</p>
  
  <p>As an aside, bing sentiment function runs through about two dozen of files and gives a different error, which seems to point to the same problem (negative sentiment not found?):</p>
  
  <pre><code>GetBingSentiment &lt;- function(file){
      fileName &lt;- glue(inputdir, file, sep = "")
      fileName &lt;- trimws(fileName)
  
      fileText &lt;- glue(read_file(fileName))
      fileText &lt;- gsub("\\$", "", fileText)       
      tokens &lt;- data_frame(text = fileText) %&gt;% unnest_tokens(word, text)
  
      # get the sentiment from the first text: 
      sentiment &lt;- tokens %&gt;%
          inner_join(get_sentiments("bing")) %&gt;% # pull out only sentiment words
          count(sentiment) %&gt;% # count the # of positive &amp; negative words
          spread(sentiment, n, fill = 0) %&gt;% # made data wide rather than narrow
          mutate(sentiment = positive - negative) %&gt;% 
          mutate(file = file) %&gt;% # add the name of our file
          mutate(year = as.numeric(str_match(file, "\\d{4}"))) %&gt;% # add the year
          mutate(city = str_match(file, "(.*?).2")[2])
  
      # return our sentiment dataframe
      return(sentiment)
  }
  
  Error in mutate_impl(.data, dots) : 
    Evaluation error: object 'negative' not found. 
  </code></pre>
  
  <p><strong>EDIT:</strong> Following the recommendation by David Klotz I edited the code to</p>
  
  <pre><code>for(i in files){ nrc_sentiments &lt;- dplyr::bind_rows(nrc_sentiments, GetNrcSentiment(i)) } 
  </code></pre>
  
  <p>As a result, instead of throwing an error the nrc generates NA if words from a certain sentiment are not found, however after 22 joinings i get a different error:</p>
  
  <p><code>Error in mutate_impl(.data, dots) : Evaluation error: object 'negative' not found.</code> </p>
  
  <p>The same error shows up when run the bing function with dplyr. Both dataframes by the time the functions reaches 22nd document contain columns for all sentiments. What may cause the error and how to can diagnose it?</p>