Tom
Tom

Reputation: 1138

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.

Upvotes: 1

Views: 904

Answers (1)

Tom
Tom

Reputation: 1138

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 = ", ")``

Upvotes: 1

Related Questions