R: why kable doesn't print inside a for loop?

后端 未结 1 374
情深已故
情深已故 2020-12-17 14:31

I\'m working a report with rmarkdown and latex. I need to print a group of tables using knitr::kable, but the don\'t print when inside a for loop.

This

相关标签:
1条回答
  • 2020-12-17 14:51

    This question is addressed here: https://github.com/yihui/knitr/issues/886

    All you need is a line break after each print call

    ---
    title: "project title"
    author: "Mr. Author"
    date: "2016-08-30"
    output: 
      pdf_document: 
        latex_engine: xelatex
        bibliography: biblio.bib
        header-includes:
           - \usepackage{tcolorbox}
    ---
    
    Text and chunks that run ok.
    
    ```{r loadLibraries}
    require(data.table)
    require(knitr)
    ```
    
    ```{r results = "asis"}
    t1 <- data.table(a = sample(letters, 10, T), b = sample(LETTERS[1:3], 10, T))
    t2 <- split(t1, t1$b)
    
    for (i in 1:length(t2)){
        print(kable(t2[[i]], col.names = c("A", "B")))
        cat("\n")
    }
    ```
    
    0 讨论(0)
提交回复
热议问题