One of the nice things about knitr is that you can easily change the colouring of R code. However, most documents are printed in black and white. So would be a good styling setting for R code when printing documents using a black and white printer?
As other commenters have mentioned, you only really have a choice of altering a few shades of grey, plus bold and italics. Here's a stylesheet in loose order of most prominent to least prominent items. Your preference may vary.
.background {
color: #ffffff;
}
.source, .output, .warning, .error, .message {
padding: 0em 1em;
border: solid 1px #f7f7f7;
}
.error, .warning, .message {
font-weight: bolder;
font-style: italic;
color: #000000;
}
.keyword {
font-weight: bolder;
color: #000000;
}
.functioncall, .package {
font-weight: bolder;
color: #202020;
}
.source, .output, .number, .argument, .formalargs, .eqformalargs, .assignement, .symbol, .prompt {
color: #404040;
}
.string {
font-weight: bold;
color: #606060;
}
.comment, .roxygencomment, .slot {
font-style: italic;
color: #808080;
}
The easiest way to make this available is to save as e.g., "knitr/themes/bw.css" in whichever library the knitr package is in. Then you can use it by calling
knit_theme$set("bw")
(Alternately, for a small amount of extra typing, you can provide knit_theme
a path to the CSS file.)
There are now grey scale themes within knitr: greyscale0
, greyscale1
and greyscale2
. You can view all knitr themes via:
library("knitr")
knit_theme$get()
To set the theme in a knitr document, add (for example) the line
knit_theme$set("greyscale2")
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