简体   繁体   中英

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()

knitr 所需的 LaTeX 输出

The following seems to have become the default format (presumably due to my inadvertent setting of a knitr option):

来自 knitr 的不良 LaTeX 输出

There's a generic function called knit_print with methods for various classes; run methods("knit_print") to see what they are with the packages you have loaded. 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. Running example(knit_print) will create a data.frame method.

From the other answer, it appears that it was the printr package which added a knit_print.data.frame method. To work around this, you can use the render chunk option, eg

```{r}
library(printr)
head(mtcars)
```

```{r render = print}
head(mtcars)
```

which yields this 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). 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM