title: Is there a way to detect a string and then remove a subset of it in R?
body: <p>I have a very large dataset from which, I want to detect a specific string, somewhere in the whole review and then remove white spaces from it. Here's an example:</p>
  <p>A string that contains <strong>Happy Meal</strong> should be replaced by <strong>HappyMeal</strong>
  or
  A string consisting of <strong>cheeseburger meal</strong> should be replaced by <strong>cheeseburgermeal</strong></p>
  <p>Here are all methods that I have tried:</p>
  <p>1.</p>
  <pre><code>data %&gt;% pull(body) %&gt;%
    str_replace_all(c(&quot;happy meal&quot; = &quot;happymeal&quot;, &quot;chicken nuggets meal&quot; = &quot;chickennuggetsmeal&quot;,
                    &quot;chicken legend meal&quot; = &quot;chickenlegendmeal&quot;,
                    &quot;double cheeseburger meal&quot; = &quot;doublecheeseburgermeal&quot;))
  </code></pre>
  <p>The code above executes without error so I have no output to share for this one but when I check the dataset the changes still do not exist.
  <em>(Edit) after assigning it, I get one long string of 5000000 characters which is not what I want, I want individual comments within the body to remain separated.</em></p>
  <p>2.</p>
  <pre><code> str_remove(str_detect((&quot;happy meal|chicken nuggets meal|chicken legend meal|double cheeseburger meal&quot;)), &quot; &quot;)
  </code></pre>
  <p>OUTPUT</p>
  <blockquote>
  <pre><code>Error in str_remove(., str_detect((&quot;happy meal|chicken nuggets
  meal|chicken legend meal|double cheeseburger meal&quot;)),  :   
  unused argument (&quot; &quot;)
  </code></pre>
  </blockquote>
  <ol start="3">
  <li></li>
  </ol>
  <pre><code>data$body &lt;- str_remove(str_detect(data$body,
   (&quot;happy meal|chicken nuggets meal|chicken legend meal|double cheeseburger meal&quot;)), &quot; &quot;)
  </code></pre>
  <p>This output also executes but returns all values in body as Booleans, which I am aware, is because <code>string _detect()</code> returns a boolean. Another way I have tried is by assigning a new variable to the whole body string, which just returns one extremely long character string. I might be making some very silly mistakes, however, I can't seem to figure out what mistake am making in obtaining strings without spaces so any help is appreciated!</p>