Search code examples
rhttrpurrr

httr::GET() can't be handled purrr::safely()?


This is probably a fundamental misunderstanding on my part, but I thought purrr::safely() captured all errors and never failed. Yet:

> purrr::safely(httr::GET('http://revolution-news.com/'))
Error in curl::curl_fetch_memory(url, handle = handle) : 
  Couldn't resolve host name

Solution

  • safely is a function wrapper, not a function call wrapper. Use

    purrr::safely(httr::GET)('http://revolution-news.com/')
    

    Notice how it wraps the function GET(), not the call to get. You could break that apart to

    safe_GET <- purrr::safely(httr::GET)
    safe_GET('http://revolution-news.com/')