1

I've been working on this R library for FTP for a while now and my most recent endeavor is trying to make a function that deletes things from an FTP server. However, I've found myself bamboozled for quite a while now by this problem.

Here's my code for deleting the files:

  ftpDelete <- function(credentials, address, directory, files) {
  status <- integer(length(files))
  names(status) <- files
  pb <- txtProgressBar(min = 0, max = length(files), style = 3)
  cd <- paste("CWD", directory)
  for (n in 1:length(files)) {
    sink("nul")
    status[n] <- tryCatch({
      dc <- paste("DELE", files[n])
      k <- curlPerform(url = getFTPURL(address), quote = c(cd, dc), userpwd = credentials, returntransfer = 1)
      0
    }, error = function(w) {
      return(1)
    })
    Sys.sleep(0.5)
    sink()
    setTxtProgressBar(pb, n)
  }
  close(pb)
  return(status)
}

Every time I run this code, it seems to print out the full directory of the FTP folder, which is INCREDIBLY irritating, especially when I apply this function on a large amount of files. Do you guys have any advice / wisdom about how to hide the output? For reference, I'm using RStudio on Windows 10, and even with using sink() around the entire function call, I still get the entire directory printed. out.

2 Answers2

0

I have had this issue and today i believe i have found a solution. There is an option verbose = F in curlperform. Please update if this works for you guys.

sveer
  • 427
  • 3
  • 16
-1

Try sink(type="message"), or better yet, suppressMessages(). You may also want to consider the curl package as an alternative to RCurl.

Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
  • Thanks for the quick answer! So I've tried both of these already and neither of them seem to work. In terms of the curl package, I've looked at it but I was wondering how difficult you think it would be to refactor everything from RCurl to curl, since it might not be worth it. Also if you have any other ideas on how to suppress the output they would be greatly appreciated. – Daniel Monteagudo Jun 15 '18 at 20:30
  • Maybe other options would be `suppressWarnings` (together with `suppressMessages`), `invisible()` or `capture.output()` around those function calls that produce console output. Do you have any suspicion as which one that could be? – SeGa Jun 15 '18 at 21:23
  • I am fairly certain it is the curlPerform function that is causing the output. It doesn't look like warnings or messages just like standard out, but for some reason none of the methods you mentioned shut it up. – Daniel Monteagudo Jun 16 '18 at 02:56
  • @DanielMonteagudo Did you find any solution regarding this? – sveer Mar 10 '20 at 10:03