KnitR在块和内联代码中如何不同地处理输出数字? [英] How are output digits handled differently by KnitR in chunks and inline code?
问题描述
我对KnitR如何以块和内联代码(\Sexpr{}
)不同地处理输出的digits
感到困惑.通常,我希望对它们进行相同的处理.一旦我了解了如何为两种类型的输出设置选项,就不会出现任何问题,而这在手册中是找不到的.请参阅下面的MWE.
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}
如果您不想编译它,则块打印3.1,而\Sexpr
打印3.14.
In case you don't feel like compiling this, the chunk prints 3.1 whereas the \Sexpr
prints 3.14.
推荐答案
根据?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.
请特别注意这只是一个建议.但是在knitr
中,默认情况下根据getOption('digits')
对内联号进行round()
Note in particular It is a suggestion only. But in knitr
, the inline numbers are round()
ed according to getOption('digits')
by default.
这篇关于KnitR在块和内联代码中如何不同地处理输出数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!