bytes.pretty <- function(n){ u <- c('', 'k', 'M', 'G', 'T') r <- 1024^(1:length(u)-1) i <- which.min(abs(512-n/r)) sprintf("%.1f%s", n/r[i], u[i]) }