title: Detect multiple strings with dplyr and stringr
body: <p>I'm trying to combine dplyr and stringr to detect multiple patterns in a dataframe. I want to use dplyr as I want to test a number of different columns. </p>
  
  <p>Here's some sample data:</p>
  
  <pre><code>test.data &lt;- data.frame(item = c("Apple", "Bear", "Orange", "Pear", "Two Apples"))
  fruit &lt;- c("Apple", "Orange", "Pear")
  test.data
          item
  1      Apple
  2       Bear
  3     Orange
  4       Pear
  5 Two Apples
  </code></pre>
  
  <p>What I would like to use is something like: </p>
  
  <pre><code>test.data &lt;- test.data %&gt;% mutate(is.fruit = str_detect(item, fruit))
  </code></pre>
  
  <p>and receive </p>
  
  <pre><code>        item is.fruit
  1      Apple        1
  2       Bear        0
  3     Orange        1
  4       Pear        1
  5 Two Apples        1
  </code></pre>
  
  <p>A very simple test works</p>
  
  <pre><code>&gt; str_detect("Apple", fruit)
  [1]  TRUE FALSE FALSE
  &gt; str_detect("Bear", fruit)
  [1] FALSE FALSE FALSE
  </code></pre>
  
  <p>But I can't get this to work over the column of the dataframe, even without dplyr:</p>
  
  <pre><code>&gt; test.data$is.fruit &lt;- str_detect(test.data$item, fruit)
  Error in check_pattern(pattern, string) : 
    Lengths of string and pattern not compatible
  </code></pre>
  
  <p>Does anyone know how to do this?</p>