(x <- c(outer(c(1,pi), 10^(-10:11))))
sum(nchar(f1 <- format(x, digits=1))) # 220
sum(nchar(f2 <- sapply(x, format, digits=1)))# 194
sum(nchar(ff1<- frmtNum(x, sci=-1L))) # 152
sum(nchar(ff2<- frmtNum(x, sci=-2L))) # 150
sum(nchar(ff <- frmtNum(x))) # 150 .. the best
sum(nchar(ff3<- frmtNum(x, sci=-3L))) # 152
## deprecation and back compatibility:
tools::assertWarning(ff3.o <- formatN(x, sci=-3L), verbose=TRUE)
stopifnot(identical(ff3.o, ff3))
noquote(rbind(f1, f2, ff1, ff, ff2, ff3))
## the best is ff (where sci differs for neg.exp and pos.ex) - for this example
## the "extreme" formatting still keeps "95%" of numerical info :
stopifnot(all.equal(x, as.numeric(frmtNum(x)), tolerance = 0.05))
Run the code above in your browser using DataLab