'RMarkdown, knitr::kable shows "\begin{table}" after knitting to pdf document

One of cells in my RMarkdown document

```{r echo=FALSE}
head(data,3) %>% knitr::kable(caption = "Pierwsze 3 wiersze ze zbioru danych Lista_1.csv", digits = 2, booktabs = T) 

gives weird result after knitting to pdf: enter image description here

Of course there shouldn't be "\begin{table}" ,"\caption{}" and "\end{table}" parts. I use knitr::kable often and it never worked this way. Does anyone know how to fix it?

Edit: I have also noticed that all section headers (like "##Section2") below the table are centered. They shouldn't.



Solution 1:[1]

I've just found this question: How do I prevent kable from leaving raw latex in the final document if I include a caption in a table? and used tip from comment (format = pandoc). It worked for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Brzoskwinia