1
votes

Ive been reading through the Rstudio Markdown tutorials trying to figure out how to do syntax highlighting on my code in a .rmd file, but cant figure it out. Anyone know how to do it? My output goal right now is .html, but that can change if needed. Thanks!

A small code snippet of what I tried. The page text works fine but the code does not highlight:

---
title: Eve Historical Market Analysis
author: 
date: 12/3/18
output:
  prettydoc::html_pretty:
    theme: cayman
    highlight: github
---
```
library(rmarkdown) #used for syntax highlighting in this document
library(shiny)
```
#read in file of item ids from website and parse
```
url = "http://eve-files.com/chribba/typeid.txt"
df = read_fwf(url, fwf_empty(url), skip = 2)
colnames = read_table(url, n_max = 1)
names(df) = names(colnames)
1
Do you want the code to run? Or just to show example code? Currently because you do not have ` - Elin
you didn't put the code in a r chunk - s.brunel
Nope that isnt expected to run- its just a snippet from the top of my file to show what I have tried so far. - Rilcon42
@s.brunel I was under the impression the ``` denoted an R chunk. Is that incorrect? - Rilcon42
@Rilcon42 ``` does not denote an R chunk unless you include {r} right after the ```, or in your case {r, eval = FALSE} (see the fourth example at this page). I think Imran Ali's answer is exactly what you're looking for. - duckmayr

1 Answers

3
votes

Just modify the r code chunks as follows, and I hope it will produce what you are looking for

```{r, echo=FALSE}
library(rmarkdown) #used for syntax highlighting in this document
library(shiny)
```
#read in file of item ids from website and parse

```{r code, eval=FALSE}
url = "http://eve-files.com/chribba/typeid.txt"
df = read_fwf(url, fwf_empty(url), skip = 2)
colnames = read_table(url, n_max = 1)
names(df) = names(colnames)
```

Output:

Output