packAlpha
packAlpha

Reputation: 1

How to change the color pattern of codes (echo = True) in an Rmarkdown file?

I'm generating a Rmarkdown file, showing the script (echo = TRUE) in the report. The code is shown in a color pattern, like in this image(https://i.sstatic.net/oAxON.png), with some in blue, some green, and some black. How can I choose a different color pattern? The green color looks not very readable. I would really appreciate any help! Thanks so much!

I tried changing the R preference - editor theme, but this does not change the color pattern in the knitted file. As this is not using the methods of color specification for plain text, I have no idea how to change this color pattern for reported codes themselves.

Upvotes: 0

Views: 171

Answers (1)

Julie Courraud
Julie Courraud

Reputation: 23

You have different highlighting styles, I found this gallery.

output:
    html_document:
        highlight: zenburn

On bookdown.org highlight specifies the syntax highlighting style. Supported styles include "default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", and "haddock". Pass null to prevent syntax highlighting.

Alternatively, you can look at different themes for the entire document, they come with different colour palettes for the output of source code.

Looking into code decoration guidelines, I don't see a way to easily pick your own colours.

For default themes:

title: Nineteen Years Later
author: Harry Potter
date: July 31, 2016
output:
  rmarkdown::html_document:
    theme: lumen

To add a prettydoc theme, install the prettydoc package, just type the one you chose at the top of your document, as explained on the prettydoc home page.

title: Nineteen Years Later
author: Harry Potter
date: July 31, 2016
output:
  prettydoc::html_pretty:
    theme: cayman
    highlight: github

Upvotes: 1

Related Questions