How are output digits handled differently by KnitR in chunks and inline code?

∥☆過路亽.° 提交于 2019-12-10 18:26:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!