[R] Setting inline hook to a function identical to default in knitr turns of exponential formatting
mlell08
mlell08 at gmail.com
Mon Jan 28 11:42:07 CET 2013
Hello List,
while dealing with a questin of 'xiaodao' (
http://r.789695.n4.nabble.com/Problem-with-large-small-numbers-in-knitr-tp4653986.html)
I noticed that copying the default inline hook function obtained by
knit_hooks$get("inline")
into a knit_hook$set(inline = <...>) call turns off exponential
fomatting in the resulting .tex file.
I used a stripped version of 'xiaodao's example:
\documentclass{article}
\begin{document}
<<>>=
a<-1e-13
b<-2.5e-10
ssrr<-123456.12
ssru<-123400.00
@
$
c=\Sexpr{a}/\Sexpr{b}
f=\Sexpr{ssrr-ssru}/\Sexpr{ssru}
$
\end{document}
so:
knit_hooks$restore()
knit_hooks$get("inline")
## yields:
## function (x)
## {
## if (is.numeric(x))
## x = round(x, getOption("digits"))
## paste(as.character(x), collapse = ", ")
## }
## <environment: namespace:knitr>
knit("FILENAME.Rnw")
## .tex-file:
## c=$10^{-13}$/$2.5\times 10^{-10}$
## f=56.12/$1.234\times 10^{5}$
## then run knit_hooks$set() with exactly the same function:
knit_hooks$set(inline= function (x)
{
if (is.numeric(x))
x = round(x, getOption("digits"))
paste(as.character(x), collapse = ", ")
}
)
knit("FILENAME.Rnw")
## .tex-File
## c=0/0
## f=56.12/123400
knit_hooks$get("inline")
## function (x)
## {
## if (is.numeric(x))
## x = round(x, getOption("digits"))
## paste(as.character(x), collapse = ", ")
## }
The only thing that changed is no <environment: namespace:knitr> is
printed anymore
Why does knitr change its output?
Regards, Moritz
More information about the R-help
mailing list