R-helpers:
What would be the absolute fastest way to make a large empty file (e.g.
filled with all zeroes) on disk, given a byte size and a given number
number of empty values. I know I can use writeBin, but the object in
this case may be far too large to store in main memory. I'm asking
An R solution is:
allocateFile - function(pathname, nbrOfBytes) {
con - file(pathname, open=wb);
on.exit(close(con));
seek(con, where=nbrOfBytes-1L, origin=start, rw=write);
writeBin(as.raw(0), con=con);
invisible(pathname);
} # allocateFile()
allocateFile(foo.bin, nbrOfBytes=985403)
Hello,
Far from the absolute fastest but apparently portable,
big - function(con, n, pass=5000){
if(file.exists(con)) unlink(con)
fc - file(con, wb)
on.exit(close(fc))
m - n %/% pass
r - n %% pass
replicate(m, writeBin(double(pass), fc))
3 matches
Mail list logo