I've tried using backticks and tildes, but they require languages. I just want a formatted code block of plain text with highlighted background.
Using eval=FALSE
and tidy=FALSE
works until reaching a keyword such as if
, the subsequent code will be color highlighted in both the .Rmd
file and the output PDF. Not specifying a language through the options removes the capability of background highlighting the code in the output.
```{r, eval=FALSE,tidy=FALSE}
loop through each species
loop through each measurement of the current species
if measurement ...
etc.
```
You can insert an R code chunk either using the RStudio toolbar (the Insert button) or the keyboard shortcut Ctrl + Alt + I ( Cmd + Option + I on macOS). There are a large number of chunk options in knitr documented at https://yihui.name/knitr/options.
RMarkdown is an extension to markdown which includes the ability to embed code chunks and several other extensions useful for writing technical reports. The rmarkdown package extends the knitr package to, in one step, allow conversion between an RMarkdown file (.Rmd) into PDF, HTML, word document, amongst others.
Code chunks in an R Markdown document contain your R code. All code chunks start and end with ``` – three backticks or graves.
Here's some sample code that renders to HTML just fine. It also renders correctly to Word and PDF.
---
title: "Untitled"
output: html_document
---
Here is some plain text.
Next, let's write some pseudo code. Note that you don't _have_ to specify a language if using plain backticks.
```
object <- [some kind of calculation]
```
If you set `eval = FALSE` you can get the highlighted background
```{r, eval = FALSE}
object <- [some kind of calculation]
Note that this; is not valid R code
```
You may find it interesting that your example works just fine for me.
```{r, eval=FALSE}
loop through each species
loop through each measurement of the current species
...
etc.
```
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With