Run an R function inline inside image shorthand ![]()

Does anyone know a trick for doing something like this in RMarkdown:

![alt text](`r my_fun(x)`)

It's the closing bracket of the function call that causes the problem. It thinks it is the end of the image location bracket.

I know a few ways round. Of course I can pre-assign the function output to an object and then just inline r my_obj within the markdown. But that is extra code. I'm trying to keep things tight if possible.

I can just do it in HTML with <img />. But the markdown shorthand is much nicer and more succinct.

I could use knitr::include_graphics(), but that doesn't seem to allow for alt text.

No big deal if not possible, I thought I would just see if anyone knows a neat way to do this.

title: "R Notebook"

x <- ""
myfunc <- function(x){x}

![alt text](`r myfunc(x)`))

Thanks - I was actually misled by RStudio's rendering of that second bracket into thinking that the format was invalid. I should have taken the time to run an example before posting, though.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.