Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I insert a variable image file in a rmarkdown pdf

The problem is simple - How do I insert a variable filename into an rmarkdown PDF? I want to do this:

---
FNL = "image.png"
---

![Some Text](params$FNL)

only I need to pass in the value for FNL when calling rmarkdown::render

The purpose is to give the image a unique ID so that users get images marked for their session.

Anyone able to help with this?

like image 524
Joe Hightower Avatar asked Nov 08 '22 09:11

Joe Hightower


1 Answers

Just use inline R evaluation (works for both HTML and PDF output):

---
title: "Example"
author: "Martin"
date: "March, 11 2017"
output: html_document
params:
  img: NULL
---

`r sprintf("![A good boy](%s)", params$img)`

Then you can render the document with the image file by calling rmarkdown::render("MyDocument.Rmd", params = list(img = "unnamed.png")).

enter image description here

like image 152
Martin Schmelzer Avatar answered Nov 15 '22 07:11

Martin Schmelzer