Ravindra Kumar Ravindra Kumar - 29 days ago 6
R Question

Displaying multiple dataframes in R markdown

I am working on a problem, where I have to print results of some calculations and send them in email using R markdown.

There are several if else conditions in the code, (around 100) every time If Else condition is met, I want to print the generated data-frame in R markdown so that it can be part of email that I will send.

The overview of code looks like-

a <- 5
b <- 6

if (a > b) {

## Print Data frame in R Markdown ##

} else if (b < a) {

## Print Data frame in R Markdown ##
}}

## email the whole result Doc generated by R markdown ##


email part I am able to figure out, but I am not able to slice it down in chunks. every time my R markdown script is failed. any clue or path forward please.

J_F J_F
Answer

I know, I posted a comment, but this solution should work:

---
title: "Untitled"
output: pdf_document
---

```{r}
a <- 5
b <- 6

 if (a > b) {

      knitr::kable(mtcars[,1:2])

    } else if (a < b)  {

      knitr::kable(mtcars[,3:4])
    }

## email the whole result Doc generated by R markdown ##
```