'How to apply code formatting to R Markdown inline code?

suppose I want to print a list of variables in my markdown file and I want to highlight them from the rest of the text using code style. For example using the names of the iris data

The variable names of the iris data set are `r paste0(names(iris), collapse = ", ")`

should return

The variable names of the iris data set are Sepal.Length, Sepal.Width, Petal.Length, Petal.Width, Species

However, if I use this approach and try to include backticks inside the inline code with e.g.

The variable names of the iris data set are `r paste0(paste0("`", names(iris), "`"), collapse = ", ")`

or any version of trying to escape the backtick character that I could come up with ended with an error message.



Solution 1:[1]

Ok... After experimenting a bit I came up with a pretty close solution to what I was looking for:

backticks around the inline code

The variable names of the iris data set are ``r paste0(names(iris), collapse = ", ")``

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tom