Search code examples
rhttr

What is a "zip stream" and how can I process in R?


Apologies upfront. This is a complete newbie question about concepts that I'm not at all familiar with. I'm also new to R!

I'm trying to access some data via a web API.

I was expecting the response to my Get to contain some simple structured data (a csv file) that I could read into a data frame in R for manipulation.

However, I'm informed that the response of the endpoint that I'm hitting is a "zip-stream".

What the heck is a "zip-stream" and how can I manipulate it in R to get the data that I need into a data frame?


Solution

  • It sounds as though the response from the API is the contents of a zip file.

    Rather than trying to read the stream you can write to a file by adding a write_disk to the httr request to capture e.g. POST(url, ....,write_disk("filename.zip")

    You can then use unzip(filename) to open up the zip and extract the files.

    The API documentation should explain the format of the files and help you choose how to best to load the resulting file and process them.

    Does this help?

    There maybe some other ideas worth trying here: Download File in R with POST while sending data