omegahat / RCurl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Progress function call back ignores return value

hadley opened this issue · comments

getURL("http://www.omegahat.org/RCurl/index.html",  
  progressfunction = function(down, up) {cat("."); 1}, 
  noprogress = FALSE)

According to http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTPROGRESSFUNCTION, this should abort the transfer.

This is needed to handle user interrupts and errors, e.g.:

safe_exit <- function(down, up) {
  tryCatch(unsafe(down, up),
    error = function(e, ...) {
      message("Error:", e$message)
      1
    },
    interrupt = function(...) {
      message("Interrupted by user")
      1
    }
  )
}

Not quite - if you returned 1L rather than 1 from the function, things would work as expected.
The proxy C routine for the progress function hands the return value from the R function to libcurl iff the return value is an INTSXP.
I've added support for taking a logical or a real in addition to the integer.
Thanks

Awesome, thanks! One other small request, is that when you return 1L you get an error message like:
"Error in function (type, msg, asError = TRUE) : Callback aborted ". The call isn't very useful here, so it'd be nice if you did stop(..., call. = FALSE).