title: How to remove characters from filenames in R?
body: <p>Due to an unrelated software error I have many files with double filenames e.g.</p>
  
  <pre><code>c("info10_file1.info10_file1.xy", "info11_file1.info11_file1.xy") 
  </code></pre>
  
  <p>I want to remove this repetition, The files should be: </p>
  
  <pre><code>c("info10_file1.xy", "info11_file1.xy")
  </code></pre>
  
  <p>I have tried using <code>sapply</code> for a file rename function, but that requires a pattern which means only patterns with <code>info10</code> will be changed.</p>
  
  <p>So running this code: </p>
  
  <pre><code>sapply(files_list,FUN=function(eachPath){
  ....file.rename(from=eachPath,to=sub(pattern='info10_file1.',replacement='',eachPath))
  })
  </code></pre>
  
  <p>Will result in:</p>
  
  <pre><code>"info10_file1.xy", "info11_file1.info11_file1.xy" 
  </code></pre>
  
  <p>An improvement can be done by setting <code>pattern='file1.info'</code> which means all files will be processed, but the number 10 or 11 in info10 or info11 will still be repeated producing this:</p>
  
  <pre><code>"info10_10_file1.xy", "info11_11_file1.xy" 
  </code></pre>
  
  <p>Is there a way to simply delete an arbitrary amount of characters? In this example it would be 13. </p>