0
votes

I am very new in R Markdown and I am trying to neatly display a list of dataframes. I know I can use Pander(my_list) easily but I also want to have the option of using kable's features to group column names and etc.

I use the following code obtained from: Unexpected behavior of kable when called from lapply or from function with print statement

````{r, results='asis'}

for(i in seq_along(my_list)) {
  print(
      kable(my_list[[i]], format = "latex", caption = paste("UG",names(my_list)[i]), longtable = TRUE) %>%
          kable_styling(font_size = 7, latex_options = "repeat_header", full_width = FALSE)
  )
}

```

The results I get when I knit the HTML output is like this:

## \begingroup\fontsize{7}{9}\selectfont
## 
## \begin{longtable}[t]{l|r|r|r|r}
## \caption{\label{tab:Shear Tables}UG 100-12}\\
## \hline
##   & Shear.Ext\_Multi.lane & Shear.Ext\_Single.lane & Shear.Int\_Multi.lane & Shear.Int\_Single.lane\\
## \hline
## \endfirsthead
## \caption[]{UG 100-12 \textit{(continued)}}\\
## \hline
##   & Shear.Ext\_Multi.lane & Shear.Ext\_Single.lane & Shear.Int\_Multi.lane & Shear.Int\_Single.lane\\
## \hline
## \endhead
## Baseline & 0.9331401 & 0.7765624 & 0.8770695 & 0.6399386\\
## \hline
## Sample1 & 0.9389007 & 0.7811566 & 0.8609600 & 0.6370761\\
## \hline
## Sample2 & 0.9344672 & 0.7802461 & 0.9011831 & 0.6705924\\
## \hline
## \end{longtable}
## \endgroup{}

``` continues 

How can I get separate tables to display in R Markdown?

1
your code chunk probably needs ```{r, results='asis'}rawr
@rawr Thank you for getting back to me my code chunk has {r Shear Tables, echo=TRUE, message=FALSE, warning=FALSE, results='asis'} and nothing prints at allMaral Dorri

1 Answers

1
votes

according to the documentation, the first argument to kable_styling is your kable, you piped it in, which is what I believe is your error

x_html <- knitr::kable(head(mtcars), "html")
kable_styling(x_html, "striped", position = "left", font_size = 7)

kable_styling_example