title: How to detect if a string contains a regex pattern using dplyr pipe mutate
body: <p>I have the following data frame:</p>
  
  
  
  <pre class="lang-r prettyprint-override"><code>library(tidyverse)
  
  dat &lt;- structure(list(peptide_id = c("PD_22374", "PD_20472", "PD_17483"
  ), peptide = c("EVHNPWNFIPDFQRSRQQHAFKKIRKHRRA", "KKEPQICTWKIQVRFSMNKKVWRKGTQKKK", 
  "NESVPKTHGDVINTGIKERRSKKAKSITKV")), row.names = c(NA, -3L), class = c("tbl_df", 
  "tbl", "data.frame"))
  
  
  dat
  #&gt; # A tibble: 3 x 2
  #&gt;   peptide_id peptide                       
  #&gt;   &lt;chr&gt;      &lt;chr&gt;                         
  #&gt; 1 PD_22374   EVHNPWNFIPDFQRSRQQHAFKKIRKHRRA
  #&gt; 2 PD_20472   KKEPQICTWKIQVRFSMNKKVWRKGTQKKK
  #&gt; 3 PD_17483   NESVPKTHGDVINTGIKERRSKKAKSITKV
  </code></pre>
  
  <p>I'd like to detect which of the rows above contain this regex pattern <code>K[KR].{1}[KR]</code>.</p>
  
  <p>We'd like to have another column which gives a YES or NO. 
  How can I go about it?</p>
  
  <p>This figure showed which rows contain that pattern:</p>
  
  <p><a href="https://i.stack.imgur.com/GLfwR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GLfwR.png" alt="enter image description here"></a></p>