[R] Quickest way to make a large "empty" file on disk?

Rui Barradas ruipbarradas at sapo.pt
Thu May 3 01:07:29 CEST 2012


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))
	if(r) writeBin(double(r), fc)

	invisible(n)
}


system.time(big("zeros", n=1e7 + 1L))
   user  system elapsed 
   0.07    0.06    0.14

Changing the default 'pass' doesn't make it faster. (On my system, Win7, R
14.2.)

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/Quickest-way-to-make-a-large-empty-file-on-disk-tp4604598p4604690.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list