2017-10-14 68 views
1

我最近開始爲區塊標籤添加前綴以幫助識別預期輸出;即對於曲線的「繪圖」,對於表格的「tbl」等。使用「plot」或「plt」前綴塊區標籤可修改數字標題

今天早上我試圖給圖表添加一個fig.cap。標題將無法正確顯示;它看起來像這樣:

(#fig:plt_cars)此標題將無法正確顯示。

我期望這樣的:

圖1:該標題將正確顯示。

玩過之後,我發現添加「plot」或「plt」作爲前綴到塊標籤會導致此問題。

以下示例演示了這一點。

--- 
title: Test Post 
author: Tim Trice 
date: '2017-10-14' 
slug: test-post 
categories: [] 
tags: [] 
--- 

```{r} 
library(ggplot2) 
``` 

```{r} 
data(cars) 
``` 

```{r cars, fig.cap = "This caption will display correctly."} 
ggplot(cars, aes(x = speed, y = dist)) + geom_point() 
``` 

```{r plt_cars, fig.cap = "This caption will not display correctly."} 
ggplot(cars, aes(x = speed, y = dist)) + geom_point() 
``` 

```{r plot_cars, fig.cap = "Nor will this caption display correctly."} 
ggplot(cars, aes(x = speed, y = dist)) + geom_point() 
``` 

在正常的Rmd文檔中,所有的標題都能正常渲染;但不是在博客中。

我使用blogdown 0.1。

我已經在Debian和Windows上驗證了這一點,但目前只有R 3.4.0。

任何人都可以告訴我爲什麼我不能使用這些前綴?

編輯:它不是前綴,而是使用分隔符「_」或「。」。

這些例子不工作:

```{r test_cars, fig.cap = "Nor will this caption display correctly."} 
ggplot(cars, aes(x = speed, y = dist)) + geom_point() 
``` 

```{r test.cars, fig.cap = "Nor will this caption display correctly."} 
ggplot(cars, aes(x = speed, y = dist)) + geom_point() 
``` 

```{r c_a_r_s, fig.cap = "Nor will this caption display correctly."} 
ggplot(cars, aes(x = speed, y = dist)) + geom_point() 
``` 

編輯2:同樣的問題適用朝着knitr :: kable字幕。

```{r tblcars} 
kable(cars, caption = "This table caption works.") 
``` 

```{r tbl_cars} 
kable(cars, caption = "This table caption does not work.") 
``` 

回答

1

Appendix A of the blogdown book

[...],你需要閱讀的the bookdown book第2章(謝2016),以瞭解更多有關這些[R降價]功能。

Section 2.4 of the bookdown book

如果你想從一個代碼塊中產生交叉引用數據或表格,請確保該塊標籤僅包含字母數字字符(a-zA-Z0-9),斜槓(/)或破折號(-)。

如果您想編號或交叉引用數字,則不支持下劃線。