Skip to content

Instantly share code, notes, and snippets.

@jeroen
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save jeroen/6fc584ea0a77bb66a533 to your computer and use it in GitHub Desktop.

Select an option

Save jeroen/6fc584ea0a77bb66a533 to your computer and use it in GitHub Desktop.
curl() connection
# Synchronous implementation of curl() connection
curl <- function(url){
con <- rawConnection(raw(0), "r+");
cat("Downloading ")
req <- httr::GET(url, httr::write_stream(function(x){
cat(".")
writeBin(x, con)
}))
httr::stop_for_status(req)
seek(con, 0)
con
}
# Does not parse-stream. Downloads all data first.
diamonds <- jsonlite::stream_in(curl("https://jeroenooms.github.io/data/diamonds.json"))
# Also does not support gzip
flights <- jsonlite::stream_in(gzcon(curl("https://jeroenooms.github.io/data/flights.json.gz")))
@jeroen
Copy link
Copy Markdown
Author

jeroen commented Nov 21, 2014

This is now possible with the new curl package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment