I have an R vector of filepaths for pdf figures I would like to put into my knitr document and knit to html. I see that I can get a single pdf to be included with
knitr::include_graphics(filepaths[1])
My filepaths vector is long and changes size between document compilations. Is there a method of including them all in one go. I had imagined this would work.
for(i in filepaths){knitr::include_graphics(i)}
Had also tried:
for(i in filepaths){ print("" ) }
knitr::include_graphics() is vectorized, so the answer is simply:
knitr::include_graphics(filepaths)
Your first solution does not work because knitr::include_graphics() needs to be the top-level expression. Your second solution does not work because you should use cat() instead of print(), and the chunk option results='asis'.
There are several advantages of using include_graphics() over cat() + results='asis'.
Try using cat instead of include_graphics. For example:
for(i in 1:length(filepaths) {
cat("")
}
This is general Markdown syntax: .
With this solution you will need to use results = "asis" in chunk header.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With