How to set the language in a html document via r markdown html

我只是一个虾纸丫 提交于 2021-02-08 08:33:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!