Is it possible to highlight specific lines in a code chunk when using beamer in RMarkdown?
Unfortunately, not that I know of.
You could look if there are some ways in LaTeX for beamer, and we can see to adapt to R Markdown usage
I think there's a fundamental problem @cderv. There's no way to insert LaTeX inside a code chunk. That seems to be a limit to R Markdown. So there's no way to have a piece of a code chunk displayed differently from the rest of the chunk. I suspect there may be a way to fake it by generating code code chunks rather than just writing them, but I suspect it would be very involved.
it depends what you mean by inside a code chunk. R Markdown (and now Quarto) is built using executable code than Pandoc conversion. With Pandoc, you can detect CodeBlock and do things with them like modify them. So technically (using Lua) it would be possible to insert some content but indeed not that easy.
With R Markdown, you can do post processing in R to modify the generated LaTeX to add some content too.
Not ideal, but possible and what tools like Bookdown do for examples.
So indeed not easy, but something that can be think of. If this is a feature we manage to do, it would probably leave in Quarto (https://quarto.org) and not in R Markdow though.
Thanks for sharing thoughts !