Binary output from getURIAsynchronous from RCurl

141 views Asked by At

depending on the API that I'm calling I receive different object types from getURIAsynchronous. When I query google api I get vector of strings but in case of Route360 the response is returned binary raw. Can I somehow force this function to receive it as a normal text?

Here is a Route360 example request with example api key from their website:

> url <- "https://service.route360.net/germany/v1/polygon?cfg=%7B%22sources%22%3A%5B%7B%22lat%22%3A52.51%2C%22lng%22%3A13.37%2C%22id%22%3A%22%22%2C%22tm%22%3A%7B%22bike%22%3A%7B%7D%7D%7D%5D%2C%22polygon%22%3A%7B%22values%22%3A%5B300%2C600%2C900%2C1200%2C1500%2C1800%5D%2C%22serializer%22%3A%22json%22%2C%22pointReduction%22%3Atrue%7D%7D&cb=jQuery21409533774398208668_1482154160827&key=YWtKiQB7MiZETbCoVsG6&_=1482154160828"
> response <- getURIAsynchronous(url)
> typeof(response)
[1] "raw"
> head(response)
     [,1]
[1,]   1f
[2,]   8b
[3,]   08
[4,]   00
[5,]   00
[6,]   00
2

There are 2 answers

1
Marichyasana On

1F8B is the file magic number for a GZIP file. You can download to a file with file extension "gz" and use gunzip("foo.txt.gz") in the R.utils package. Or there might be a more simple way to work with data in memory without having to download it again.

0
abenrob On

using cURL directly,I'd pass the --compressed flag. Without explicitly being an R user, I'd imagine that's settable in the curlOptions?