To print a number, you can consider it as a string and use subit to format it:
changeSciNot <- function(n) {
output <- format(n, scientific = TRUE)
output <- sub("e", "*10^", output)
output <- sub("\\+0?", "", output)
output <- sub("-0?", "-", output)
output
}
Some examples:
> changeSciNot(5)
[1] "5*10^0"
> changeSciNot(-5)
[1] "-5*10^0"
> changeSciNot(1e10)
[1] "1*10^10"
> changeSciNot(1e-10)
[1] "1*10^-10"
source
share