Using flextable in r markdown loop not producing tables

user2547973

I have many tables to create and am trying to create them in a loop. I'm using flextable with rmarkdown inside rstudio. Using print(theFlextable) command in a loop produces a list of text rather than the table. This happens for docx and html output types. If I don't use a loop flextable renders correctly. Here is a demo:

---
title: "Demo"
output: word_document
---

```{r setup, include=FALSE}
library(flextable)
```
## This Works
```{r iris, echo=F, message=F, error=F, results='asis'}
ft<-flextable(iris[1:10,])
ft
```
## This produces no output
```{r echo=F, message=F, error=F, results='asis'}
doThese<-c("setosa","virginica")
for (i in doThese){
  tbl<-subset(iris, Species==i)
  ft<-flextable(tbl[1:10,])
  ft
}
```
## This produces incorrect output
```{r echo=F, message=F, error=F, results='asis'}
doThese<-c("setosa","virginica")
for (i in doThese){
  tbl<-subset(iris, Species==i)
  ft<-flextable(tbl[1:10,])
  print(ft)
  cat("\n\n")
}
``` 

This is the output in word of the last block above:

type: flextable object. col_keys: Sepal.Length, Sepal.Width, Petal.Length, Petal.Width, Species header has 1 row(s) body has 10 row(s) original dataset sample: Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa

type: flextable object. col_keys: Sepal.Length, Sepal.Width, Petal.Length, Petal.Width, Species header has 1 row(s) body has 10 row(s) original dataset sample: Sepal.Length Sepal.Width Petal.Length Petal.Width Species 101 6.3 3.3 6.0 2.5 virginica 102 5.8 2.7 5.1 1.9 virginica 103 7.1 3.0 5.9 2.1 virginica 104 6.3 2.9 5.6 1.8 virginica 105 6.5 3.0 5.8 2.2 virginica

user2547973

I'm not sure if this is the correct answer but I used this to solve my problem:

Looping through code in knitr and rmarkdown

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Regression Tables in R Markdown / rmarkdown (html/pdf)

分類Dev

For loop producing unexpected results in C

分類Dev

How to print References using R Markdown with Tufte

分類Dev

Create markdown frequency table using weights in R

分類Dev

Web scraping: Combining tables in for-loop in R

分類Dev

Formatting multiple columns with flextable r package

分類Dev

Using "for" loop in r with a table

分類Dev

irr出力からr-markdownのサマリーテーブル(flextable)を生成するにはどうすればよいですか?

分類Dev

Generating markdown tables in Haskell with Pandoc

分類Dev

Format data to create neat table in R markdown using kable

分類Dev

Disable warning when using large datatables in R markdown

分類Dev

for loop of subjobs using qsub R

分類Dev

optparse producing NULL values in R script

分類Dev

Why is my print statement producing no output after a while loop?

分類Dev

How to resolve the following program with a for loop into producing an appropriate output?

分類Dev

How to resolve the following program with a for loop into producing an appropriate output?

分類Dev

Problems of reshape in R markdown

分類Dev

Create Memo in R Markdown

分類Dev

R Fastest way to write for loop using vectorization

分類Dev

Adding Elements to List using For Loop in R

分類Dev

Freemarker Loop to write tables

分類Dev

Creating html tables in R using the tab_model function

分類Dev

Why is R HTTR content statement not producing the expected request body?

分類Dev

Python 3.6 Regex Producing Unexpected Results (despite using string literals)

分類Dev

2 Logo in R Markdown on PDF

分類Dev

Is it possible to automate R markdown files?

分類Dev

Mathematical equation tool for R markdown

分類Dev

FlextableをpngとしてRに保存する方法

分類Dev

R: how to center output in R markdown

Related 関連記事

  1. 1

    Regression Tables in R Markdown / rmarkdown (html/pdf)

  2. 2

    For loop producing unexpected results in C

  3. 3

    How to print References using R Markdown with Tufte

  4. 4

    Create markdown frequency table using weights in R

  5. 5

    Web scraping: Combining tables in for-loop in R

  6. 6

    Formatting multiple columns with flextable r package

  7. 7

    Using "for" loop in r with a table

  8. 8

    irr出力からr-markdownのサマリーテーブル(flextable)を生成するにはどうすればよいですか?

  9. 9

    Generating markdown tables in Haskell with Pandoc

  10. 10

    Format data to create neat table in R markdown using kable

  11. 11

    Disable warning when using large datatables in R markdown

  12. 12

    for loop of subjobs using qsub R

  13. 13

    optparse producing NULL values in R script

  14. 14

    Why is my print statement producing no output after a while loop?

  15. 15

    How to resolve the following program with a for loop into producing an appropriate output?

  16. 16

    How to resolve the following program with a for loop into producing an appropriate output?

  17. 17

    Problems of reshape in R markdown

  18. 18

    Create Memo in R Markdown

  19. 19

    R Fastest way to write for loop using vectorization

  20. 20

    Adding Elements to List using For Loop in R

  21. 21

    Freemarker Loop to write tables

  22. 22

    Creating html tables in R using the tab_model function

  23. 23

    Why is R HTTR content statement not producing the expected request body?

  24. 24

    Python 3.6 Regex Producing Unexpected Results (despite using string literals)

  25. 25

    2 Logo in R Markdown on PDF

  26. 26

    Is it possible to automate R markdown files?

  27. 27

    Mathematical equation tool for R markdown

  28. 28

    FlextableをpngとしてRに保存する方法

  29. 29

    R: how to center output in R markdown

ホットタグ

アーカイブ