This question already has an answer here:
- How to disable scientific notation? 1 answer
Question: How can I use paste
without 100000
becoming 1e+05
?
Sorry in advance if this question seems frivolous (but it has resulted in a bug in my code). I use R to call an external script, so when I say e.g. paste("abc",100000)
I want it to output "abc 100000"
and not "abc 1e+05"
.
Here's an example of what it looks like on my screen:
> paste("abc",100000)
[1] "abc 1e+05"
> paste("abc",100001)
[1] "abc 100001"
This results in the bizarre behaviour that my script works for the input "100001" but not "100000".
I realise I could create a script to convert numbers to strings however I like, but I feel I shouldn't do this if there is an internal way to do the same thing (I suspect there is some "method" I'm missing).
[If it helps, I'm on Ubuntu 12.04.1 LTS ("precise"), running R version 2.14.1 (2011-12-22) in a terminal.]
Alternatively
format
may be simpler thansprintf
especially when you want to change how decimals are displayed:Alternatively, you can use integers which don't get printed in scientific notation. You can specify that your number is an integer by putting an "L" behind it, or doing as.integer.
See
?options
, particularlyscipen
:Alternatively, control formatting tightly the old-school way via
sprintf()
: