Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
读取R中长度不确定的二进制数据_R_Binaryfiles - Fatal编程技术网

读取R中长度不确定的二进制数据

读取R中长度不确定的二进制数据,r,binaryfiles,R,Binaryfiles,我想直接从R中的URL读取长度不确定的二进制文件。使用readBin从URL读取而不指定文件大小是行不通的 anImage <- readBin('http://user2010.org/pics/useR-large.png','raw') anImage这会将文件下载到工作目录,但不会直接下载到内存中 download.file('http://user2010.org/pics/useR-large.png“,”anImage.png“ Rcurl包也可以执行您想要的操作。(由于

我想直接从R中的URL读取长度不确定的二进制文件。使用
readBin
从URL读取而不指定文件大小是行不通的

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

anImage这会将文件下载到工作目录,但不会直接下载到内存中

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


Rcurl包也可以执行您想要的操作。(由于SO限制,链接未发布)

如果要将“n”设置为合理的大,请读取文件,检查可能的溢出,并在必要时重试,这是一个简单的解决方案

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