sebastian-c sebastian-c - 1 year ago 85
R Question

How do I include backticks in an Rstudio code snippet?

I'm writing a snippet to create the following slide header in a markdown file which is literally as follows:

--- .slide x:`r x("Methods")` y:`r y("Methods")`

I want to write a snippet that allows me to type in
in both fields. The problem is that the backticks are causing the the snippet to be evaluated, not typed.

I'm aware that in this case I could write code that means I don't need the backticks, but I was looking for a way to include backticks in snippets generally.

Answer Source

I found a verbose way of solving the issue. If you replace all the literal backticks with

`r "\u0060"`

That causes that snippet to be evaluated which produces a literal backtick. The only catch I've found is that the next time you evaluate something in R (causing warning messages to appear), you'll get:

Warning message:
In if (matches == -1) return(snippet) :
  the condition has length > 1 and only the first element will be used