tags:

views:

118

answers:

2

I would like to read a binary file -- of indeterminate length -- directly from a URL in R. Using readBin to read from a URL, without specifying the file size, does not work.

 anImage <- readBin('http://user2010.org/pics/useR-large.png','raw')

Is there another approach that would allow this?

+1  A: 

This will download the file to the working directory, but not directly into memory.

download.file('http://user2010.org/pics/useR-large.png', 'anImage.png')

The Rcurl package may also do what you want. (link not posted because of SO restrictions)

Peter
Here's a link to RCurl on Crantastic: http://crantastic.org/packages/RCurl
dataspora
+1  A: 

A simple solution if to set 'n' to be reasonably large, read the file, check for possible overflow, and try again if necessary.

N <- 1e7
repeat
{
   anImage <- readBin(filename, 'raw', n=N)
   if(length(anImage) == N) N <- 5 * N else break
}
Richie Cotton