when displaying a number with inline-code with more than four digits like
`r 21645`
the result in a knitted html-file is this: 2.164510^{4}
(in reality inside the inline-hook there is a calculation going on which results in 21645). Even though I just want it to print the number, like so: 21645
. I can easily fix this for one instance wrapping it inside as.integer
or format
or print
, but how do I set an option for the whole knitr-document so that it prints whole integers as such (all I need is to print 5 digits)? Doing this by hand gets very annoying. Setting options(digits = 7)
doesnt help. I am guessing I would have to set some chunk-optionor define a hook, but I have no idea how
You can disable scientific notation in the entire R session by using the scipen option. Global options of your R workspace. Use options(scipen = n) to display numbers in scientific format or fixed.
If you want to avoid scientific notation for a given number or a series of numbers, you can use the format() function by passing scientific = FALSE as an argument.
First of all, create a vector and its plot using plot function. Then, use options(scipen=999) to remove scientific notation from the plot.
(1) Right-click a cell where you want to remove scientific notation, and (2) choose Format Cells… 2. In the Format Cells window, (1) select the Number category, (2) set the number of decimal places to 0, and (3) click OK. Now the scientific notation is removed.
I already solved it, just including the following line of code inside the setoptions-chunk in the beginning of a knitr document:
options(scipen=999)
resolves the issue, like one can read inside this answer from @Paul Hiemstra:
https://stackoverflow.com/a/25947542/4061993
from the documentation of ?options
:
scipen: integer. A penalty to be applied when deciding to print numeric values in fixed or exponential notation. Positive values bias towards fixed and negative towards scientific notation: fixed notation will be preferred unless it is more than scipen digits wider.
If you don't want to display scientific notation in this instance, but also don't want to disable it completely for your knitr
report, you can use format()
and set scientific=FALSE
:
`r format(21645, scientific=FALSE)`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With