title: R download.file() rename the downloaded file, if the filename already exists
body: <p>In R, I am trying to download files off the internet using the download.file() command in a simple code (am complete newbie). The files are downloading properly. However, if a file already exists in the download destination, I'd wish to rename the downloaded file with an increment, as against an overwrite which seems to be the default process.</p>
  
  <pre><code>nse.url = "https://www1.nseindia.com/content/historical/DERIVATIVES/2016/FEB/fo04FEB2016bhav.csv.zip"
  nse.folder = "D:/R/Download files from Internet/"
  nse.destfile = paste0(nse.folder,"fo04FEB2016bhav.csv.zip")
  download.file(nse.url,nse.destfile,mode = "wb",method = "libcurl")
  </code></pre>
  
  <p>Problem w.r.t to this specific code: if "fo04FEB2016bhav.csv.zip" already exists, then get say "fo04FEB2016bhav.csv(2).zip"?</p>
  
  <p>General answer to the problem (and not just the code mentioned above) would be appreciated as such a bottleneck could come up in any other situations too.</p>