[英]Which knitr option controls typeset vs. code-like output from knitr (LaTeX)
What controls the difference between these two outputs?是什么控制了这两个输出之间的差异?
To produce the desired R-like output in the first image, I had to add %>% print()
为了在第一张图片中生成所需的 R-like output,我必须添加%>% print()
The following seems to have become the default format (presumably due to my inadvertent setting of a knitr option):以下似乎已成为默认格式(可能是由于我无意中设置了 knitr 选项):
There's a generic function called knit_print
with methods for various classes;有一个名为knit_print
的通用 function,其中包含各种类的方法; run methods("knit_print")
to see what they are with the packages you have loaded.运行methods("knit_print")
以查看它们与您加载的包有什么关系。 If your final object (which probably has classes "tbl_df"
, "tbl"
, and "data.frame"
) has a class for which there's a knit_print
method, that's what it will use.如果您的最终 object(可能有类"tbl_df"
、 "tbl"
和"data.frame"
)有一个 class,其中有一个knit_print
方法,这就是它将使用的内容。 Running example(knit_print)
will create a data.frame
method.运行example(knit_print)
将创建一个data.frame
方法。
From the other answer, it appears that it was the printr
package which added a knit_print.data.frame
method.从另一个答案来看,似乎是printr
package 添加了knit_print.data.frame
方法。 To work around this, you can use the render
chunk option, eg要解决此问题,您可以使用render
块选项,例如
```{r}
library(printr)
head(mtcars)
```
```{r render = print}
head(mtcars)
```
which yields this output:产生这个 output:
After reading vi.nette('knit_print', package = 'knitr')
I discovered that in my case the cause was that I had blindly added library(printr)
in the preamble of my Rnw file, which produced formatted output (as in my second inserted image).阅读vi.nette('knit_print', package = 'knitr')
后,我发现在我的情况下,原因是我在我的 Rnw 文件的序言中盲目地添加了library(printr)
,它产生了格式化的 output(如我的第二个插入的图像)。 When I commented out that line, the output was as you would see it in interacting with R in the console (as in the first image).当我注释掉该行时,output 就像您在控制台中与 R 交互时看到的那样(如第一张图片所示)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.