问题
I am using a .Rmd documment and rendering to html_document. The prefix of my tables come as "Table", however, I want it in my first language. As in pdf_document, I want to set the language of my report to portuguese, like this:
---
title: "Code"
author: "Guilherme"
date: "May 9, 2017"
lang: "pt-br"
output:
html_document: default
---
Is there a way to do that?
回答1:
There is no way to do this with the htmlTable
package because the "Table no" bit is hardcoded into this package (see the source code).
If you want localization, thus, you'll need to use another way to produce captions. An alternative is the captioner package.
```{r}
library(htmlTable)
library(captioner)
table_nums <- captioner(prefix = "Tabela") # from google translate :)
htmlTable(table(iris$Species,iris$Species),
caption = table_nums("desc_iris", "Descriptive Measuraments of..."))
```
回答2:
If I knit:
---
title: "Code"
author: "Guilherme"
date: "May 9, 2017"
lang: "pt-br"
output:
bookdown::html_document2
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r cars}
library(knitr)
kable(mtcars[1:5,2:3], caption = "Azul")
```
with a file called _bookdown.yml
in the same directory with this content:
language:
label:
fig: "Figura "
tab: "Tabela "
it produces the labeling correctly, as @Sébastian suggested in the comments
来源:https://stackoverflow.com/questions/43871475/how-to-set-the-language-in-a-html-document-via-r-markdown-html