I trying to use kableExtra in RMarkown for a text table as the following example:
text_tbl <- data.frame(
Items = c("Item 1", "Item 2", "Item 3"),
Features = c(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vehicula tempor ex. Morbi malesuada sagittis turpis, at venenatis nisl luctus a. ",
"In eu urna at magna luctus rhoncus quis in nisl. Fusce in velit varius, posuere risus et, cursus augue. Duis eleifend aliquam ante, a aliquet ex tincidunt in. ",
"Vivamus venenatis egestas eros ut tempus. Vivamus id est nisi. Aliquam molestie erat et sollicitudin venenatis. In ac lacus at velit scelerisque mattis. "
)
)
kbl(text_tbl, booktabs = T) %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T, color = "red") %>%
column_spec(2, width = "30em")
However I would to change the text of the table by adding operators in one column and the example with some explanation in another, exactly to this site: https://www.tutorialspoint.com/r/r_operators.htm.
I produced this following code, with some variations, but not worked.
text_tbl <- data.frame(
Items = c(" <- ", " %in% "),
Features = c(
" Here it's an example: $x <- 3$",
" Here it's an example: $c(1, 1, 1, 2, 5, 8, 10) %in% 1$ "
)
)
kbl(text_tbl, booktabs = T) %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T, color = "red") %>%
column_spec(2, width = "30em")
Trying to be more specific I would to know:
1 - How can I add operators in a data frame that I will used in a table created by kable()? 2 - How can I add a code in a data frame that I will run out inside a table created by kable()?
Both questions I would to execute in rmarkdown.
Thank you
Maybe this could help you:
---
title: "Untitled"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(kableExtra)
```
```{r}
text_tbl <- data.frame(
Items = c(" $<-$ ", " $$\\%$$in$$\\%$$ "),
Features = c(
" Here it's an example: $x <- 3$",
" Here it's an example: $c(1, 1, 1, 2, 5, 8, 10) $$\\%$$in$$\\%$$ 1$ "
)
)
kbl(text_tbl, booktabs = T, escape = F) %>%
kable_styling(full_width = F) %>%
column_spec(1, bold = T, color = "red") %>%
column_spec(2, width = "30em")
```
1 - escape = F
was added to the function kbl
2 - To insert %, you need this: $$\\%$$