Conditional markup blocks?

1,232 views
Skip to first unread message

Keith Hughitt

unread,
Jun 7, 2013, 5:19:06 PM6/7/13
to kn...@googlegroups.com
Hello,

Does anyone know if it is possible to conditionally knit blocks of markdown, etc.?

For example, it would be nice to be able to do something like:

```{r start}
if (x == TRUE) {
```
some text here...

```{r finish}
}
```

This would be useful to be able to mark off large sections of text that should only be displayed under certain conditions.
Keith

Yihui Xie

unread,
Jun 7, 2013, 5:23:53 PM6/7/13
to Keith Hughitt, kn...@googlegroups.com
You can make use of child documents.

```{r main}
x = TRUE # or FALSE
```

Then

```{r test, child = if (x == TRUE) 'child-a.Rmd' else 'child-b.Rmd'}
```

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
Message has been deleted
Message has been deleted

Keith Hughitt

unread,
Jun 16, 2013, 12:13:05 PM6/16/13
to kn...@googlegroups.com
Works perfect. Thanks, Yihui!

Dean Attali

unread,
Sep 18, 2014, 5:53:11 PM9/18/14
to kn...@googlegroups.com
Interesting workaround :)
Are there plans to add more concrete support for conditional blocks? A markdown document with several small conditional blocks will quickly get very messy and complicated if we need to use several different .Rmd files for this.

On Sunday, 16 June 2013 09:13:05 UTC-7, Keith Hughitt wrote:
Works perfect. Thanks, Yihui!

Yihui Xie

unread,
Sep 23, 2014, 3:33:11 PM9/23/14
to Dean Attali, knitr
Sorry, it is a little bit complicated for me to implement. Jeff
Horner's brew package has done it long time ago, though:
http://cran.rstudio.com/web/packages/brew/

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Web: http://yihui.name
Reply all
Reply to author
Forward
0 new messages