无法打印带有有线和for循环的表格

时间:2020-10-21 05:25:00

标签: r r-markdown

这将作为常规代码打印,但完全不使用rmarkdown打印。问题可能出在代码的压缩和样式选项中。有什么想法吗?

{r printing,echo=FALSE, cache=FALSE, results='asis'}


library(tidyverse)
library(kableExtra)
library(dotwhisker)
library(broom)


kbl <- function (df) {
  cat("\n\n")
  df2<-kable(df) %>% kable_styling(bootstrap_options = c("striped", "condensed"))
  print(df2)
  cat("\n\n")
}


df <- mtcars
nested_inter <- mtcars %>% group_by(gear) %>% 
  nest() ## groups all the data by the sub series
nested_inter <- nested_inter  %>% 
  mutate (model =  map(data, 
                       ~lm(formula = mpg ~ cyl + drat + hp +wt , data = .)))


  for(i in seq(nrow(nested_inter))) {
    kbl(glance(nested_inter$model[[i]]))
    t1<- nested_inter$model[[i]] %>% broom::tidy() 
    kbl(t1)
  }
    

谢谢!

1 个答案:

答案 0 :(得分:1)

您还在寻找什么吗?您的代码示例没有正确的Rmarkdown语法。

---
title: "Kable output"
output: html_document
---
```{r printing,echo=FALSE, message = FALSE, warning =     FALSE,cache=FALSE, results='asis'}


library(tidyverse)
library(kableExtra)
library(dotwhisker)
library(broom)


kbl <- function (df) {
  cat("\n\n")
  df2<-kable(df) %>% kable_styling(bootstrap_options =     c("striped", "condensed"))
  print(df2)
  cat("\n\n")
}


df <- mtcars
nested_inter <- mtcars %>% group_by(gear) %>% 
  nest() ## groups all the data by the sub series
nested_inter <- nested_inter  %>% 
  mutate (model =  map(data, 
                       ~lm(formula = mpg ~ cyl + drat + hp     +wt , data = .)))


for(i in seq(nrow(nested_inter))) {
  kbl(glance(nested_inter$model[[i]]))
  t1<- nested_inter$model[[i]] %>% broom::tidy() 
  kbl(t1)
}
```

enter image description here