简体   繁体   English

如何更改Knitr SQL块的表标题?

[英]How to change table captions for knitr sql chunks?

Here is a knitr chunk that connects to a database and a sql chunk that runs a query on the database: 这是一个连接到数据库的编织程序块和一个在数据库上运行查询的sql块:

```{r dbConnect}
con <- RMySQL::dbConnect(RMySQL::MySQL(), dbname = "test")
```

```{sql rowsintable, connection=con}
select count(*) from tablename;
```

I use this document to generate a PDF file. 我使用此文档生成PDF文件。 In the pdf document, the table returned by the sql chunk has a caption: "Table 1: 1 records". 在pdf文档中,sql块返回的表带有标题:“表1:1条记录”。 How can I change this caption? 如何更改此标题?

This question is related, but doesn't use SQL chunks, and it sets the caption inside an R function, not in the knitr chunk options . 这个问题是相关的,但是不使用SQL块,而是在R函数内而不是在knitr 块选项中设置标题。

You can use the chunk option tab.cap , eg 您可以使用块选项tab.cap ,例如

```{r dbConnect}
con <- RMySQL::dbConnect(RMySQL::MySQL(), dbname = "test")
```

```{sql rowsintable, connection=con, tab.cap="Here is the caption."}
select count(*) from tablename;
```

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

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