簡體   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