title: fuzzy version of stringr::str_detect for filtering dataframe
body: <p>I've got a database with free text fields that I want to use to <code>filter</code> a <code>data.frame</code> or <code>tibble</code>. I could perhaps with lots of work create a list of all possible misspellings of my search terms that currently occur in the data (see example of all the spellings I had of one term below) and then I could just use <code>stringr::str_detect</code> as in the example code below. However, this will not be safe when there might be more misspellings in the future. If I'm willing to accept some limitations / make some assumptions (e.g. how far the edit distance between the misspellings could be, or in terms of some other difference, that people won't use completely different terms etc.), is there some simple solution for doing a fuzzy version of <code>str_detect</code>?</p>
  <p>As far as I could see the obvious packages like <code>stringdist</code> do not seem to have a function that directly does this. I guess I could write my own function that applies something like <code>stringdist::afind</code> or <code>stringdist::amatch</code> to each element of a vector and post-processes the results to eventually return a vector of <code>TRUE</code> or <code>FALSE</code> booleans, but I wonder whether this function does not exist somewhere (and is more efficiently implemented than I would do it).</p>
  <p>Here's an example that illustrates how with <code>str_detect</code> I might miss one row I would want:</p>
  <pre><code>library(tidyverse)
  
  search_terms = c(&quot;preclinical&quot;, &quot;Preclincal&quot;, &quot;Preclincial&quot;, &quot;Preclinial&quot;, 
                   &quot;Precllinical&quot;, &quot;Preclilnical&quot;, &quot;Preclinica&quot;, &quot;Preclnical&quot;, 
                   &quot;Peclinical&quot;, &quot;Prclinical&quot;, &quot;Peeclinical&quot;, &quot;Pre clinical&quot;, 
                   &quot;Precclinical&quot;, &quot;Preclicnial&quot;, &quot;Precliical&quot;, &quot;Precliinical&quot;, 
                   &quot;Preclinal&quot;, &quot;Preclincail&quot;, &quot;Preclinicgal&quot;, &quot;Priclinical&quot;)
  
  example_data = tibble(project=c(&quot;A111&quot;, &quot;A123&quot;, &quot;B112&quot;, &quot;A224&quot;, &quot;C149&quot;),
                        disease_phase=c(&quot;Diabetes, Preclinical&quot;, &quot;Lipid lowering, Perlcinical&quot;, 
                                        &quot;Asthma, Phase I&quot;, &quot;Phase II; Hypertension&quot;, &quot;Phase 3&quot;),
                        startdate = c(&quot;01DEC2018&quot;, &quot;17-OKT-2017&quot;, &quot;11/15/2019&quot;, &quot;1. Dezember 2004&quot;, &quot;2005-11-30&quot;)) 
  
  # Finds only project A111, but not A123
  example_data %&gt;%
    filter(str_detect(tolower(disease_phase), paste0(tolower(search_terms), collapse=&quot;|&quot;)))
  </code></pre>