gsub function in TM package to remove URLS does not remove the entire string
<p>I am using this function in a script using the r text mining package (tm) to eliminate URLs from tweets. To my surprise, after clean up there are some leftover "http" words and also fragments from the URL itself (such as t.co). It looks like some of the URLS are completely wiped out, while some other are merely broken down into components. What could be the cause? NOTE: I took the . in the t.co URL. StackOverflow does not allow submitting URLs to t.co addresses.</p>

<pre><code>toSpace &lt;- content_transformer(function (x , pattern ) gsub(pattern, " ", x))
trumpcorpus1020to1109 &lt;- tm_map(trumpcorpus1020to1109, toSpace, "/")
trumpcorpus1020to1109 &lt;- tm_map(trumpcorpus1020to1109, toSpace, "@")
trumpcorpus1020to1109 &lt;- tm_map(trumpcorpus1020to1109, toSpace, "\\|")
removeURL &lt;- function(x) gsub("(f|ht)tp(s?)://(.*)[.][a-z]+", "", x)
trumpcorpus1020to1109 &lt;- tm_map(trumpcorpus1020to1109, removeURL)
</code></pre>

<p>text before cleaning</p>

<p><code>VOTE TODAY! Go to https://tco/KPQ5EY9VwQ to find your polling location. We are going to Make America Great Again!â€¦ https://tco/KPQ5EY9VwQ</code></p>

<p>text after cleaning</p>

<p><code>vote today go https tco mxraxyntjy find polling location going make america great https tco kpqeyvwq</code></p>