繁体   English   中英

编辑默认的编织器pdf

[英]Edit a default knitr pdf

经过多次测试,然后尝试使用knitr从脚本中获取pdf。 几乎所有内容都正确,但是默认输出出现一些问题:Date和sessionInfo。 kableExtra库也让我出错。

我没有使用R-studio ...

我的脚本示例:

library(xtable)
library(knitr)
library(kableExtra)

#My first pdf with knitr
data(mtcars)

tabla=mtcars%>%
count(am) 

kable(tabla, caption="tabla uno")

我的命令来编译脚本并获取pdf:

library(knitr)
setwd("C:/Users/Desktop")
knitr::stitch("C:/Users/Desktop/script.R")

在下面的pdf结果中,您可以看到pdf文档以日期开头,以sessionInfo结尾。 我想编辑日期并放入自己的标题和文本,也想删除sessionInfo。 您还可以看到电缆表位于文档的末尾,并且顺序不正确。 我也尝试添加echo = FALSE,以避免使用show命令制作表格,但没有成功...:

pdf1 pdf2

我建议您使用YAML标头创建文档,以设置诸如作者,日期和标题之类的变量。 然后,您可以将常规文本与代码块结合在一起,如下所示。

---
title: "Untitled"
author: "Rodrigo"
date: "9/9/2019"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(dplyr)
library(xtable)
library(knitr)
library(kableExtra)

```

# My first pdf with knitr

Some random text followed by a code block.
```{r}
# A comment
data(mtcars)

tabla=mtcars%>%
count(am) 
```

Here's the table. The code that printed the table has been supressed with `echo = FALSE`.

```{r echo = FALSE}
kable(tabla, caption="tabla uno") %>%
  kable_styling(latex_options = "hold_position")
```

More text

输出看起来像这样: 在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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