Generate Dynamic R Markdown Blocks

Try knit_expand(): Automate Chunks of Analysis in R Markdown ======================================================== “`{r setup, echo=FALSE} library(knitr) “` “`{r run-numeric-md, include=FALSE} out = NULL for (i in as.character(unique(iris$Species))) { out = c(out, knit_expand(text=”#### Species = {{i}}”)) } “` `r paste(knit(text = out), collapse=”\n”)` You can also create a template file like ‘child.rmd’ and put this in your for … Read more

Subfigures or Subcaptions with knitr?

knitr (>= v1.5) supports subfigures. You can use the chunk option fig.subcap. Here is a minimal example. \documentclass{article} \usepackage{subfig} \begin{document} <<fig-sub, fig.cap=’two plots’, fig.subcap=c(‘one plot’, ‘the other one’), out.width=”.49\\linewidth”>>= plot(1:10) plot(rnorm(10), pch=19) @ \end{document}

How to hold figure position with figure caption in pdf output of knitr?

For me adding the float package and then \floatplacement{figure}{H} in YAML solved the issue like : — title: “test” date: “`r Sys.Date()`” output: pdf_document : keep_tex: true number_sections: true header-includes: \usepackage{booktabs} \usepackage{longtable} \usepackage{array} \usepackage{multirow} \usepackage[table]{xcolor} \usepackage{wrapfig} \usepackage{float} \floatplacement{figure}{H} —