如何避免在每个 Sexpr{} 中使用 round()? [英] How to avoid using round() in every Sexpr{}?
问题描述
在使用 Sweave/knitr 时,有没有办法避免函数 round()
?在每个 Sexpr{}
中写 round(,2)
真的很烦人.我希望整个文档保留两位小数.
Is there a way to avoid the function round()
when using Sweave/knitr? It's really annoying to write round(,2)
in every Sexpr{}
. I would like to have two decimal places through the whole document.
感谢您的帮助
Mac
Thanks for your help
Macs
推荐答案
如果你读过动机knitr
包的a>,你大概知道我是最讨厌的人round()
在 Sexpr{}
中最多.我很久以前就向 R core 建议过 Sweave,但它被忽略了,所以我开始了自己的包.
If you have read the motivation of the knitr
package, you probably know I'm the person who hates round()
inside Sexpr{}
most. I suggested this to R core long time ago for Sweave but it was ignored, so I started my own package.
虽然 Josh O'Brien 的回答是绝对正确的,但我应该说你真的只需要 options(digits = 2)
和 knitr
,没有必要重置默认内联挂钩,因为默认挂钩尊重此选项.
Although the answer by Josh O'Brien is absolutely correct, I should say you really only need options(digits = 2)
with knitr
, and there is no need to reset the default inline hook because the default hook respects this option.
这篇关于如何避免在每个 Sexpr{} 中使用 round()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!