问题
I am confused about how KnitR handles the digits
of output differently in chunks and in inline code with \Sexpr{}
. Generally, I want them to be handled the same. This should not pose any problem once I understand how to set the options for both types of output, which I have not found in the manual. Please see the MWE below.
\documentclass[12pt, english, oneside]{amsart}
\begin{document}
<<>>=
options(digits=2)
pi
@
\Sexpr{pi}
\end{document}
In case you don't feel like compiling this, the chunk prints 3.1 whereas the \Sexpr
prints 3.14.
回答1:
According to ?options
:
‘digits’: controls the number of digits to print when printing
numeric values. It is a suggestion only. Valid values are
1...22 with default 7. See the note in ‘print.default’ about
values greater than 15.
Note in particular It is a suggestion only. But in knitr
, the inline numbers are round()
ed according to getOption('digits')
by default.
来源:https://stackoverflow.com/questions/15313224/how-are-output-digits-handled-differently-by-knitr-in-chunks-and-inline-code