Quantcast
Channel: RMarkdown - Change Inline Code Color *without changing workflow* - Stack Overflow
Viewing all articles
Browse latest Browse all 3

RMarkdown - Change Inline Code Color *without changing workflow*

$
0
0

I teach an introductory statistics course using R Markdown in RStudio (Server). We have students knit to html_notebooks, and we often have them use inline code to report various elements of their statistical analyses. It'd be really helpful for grading purposes if we could have the result of inline code output in a different color -- that way we could easily see if they were indeed using inline code or if they copy-pasted a number from their output into raw text.

There's a couple of ideas for solutions posted here, but these won't super work in my case. These are introductory students who are generally kinda afraid of RStudio to begin with, so asking them to do anything complicated with text_spec or sprintf will likely cause mild riots. I really need something that won't change students' workflow at all.

I wonder if there's any way to configure things either on the backend in RStudio Server (maybe by messing with knitr?), or through some kind of <style> tag wizardry in the preamble, so that inline code will print its results in a different color.

Thanks!

EDIT: Arthur Berg below has provided something that's almost exactly what I need. Here's a MWE:

---title: "test knit_hook"output: html_document---```{r, setup, include="FALSE"}knitr::knit_hooks$set(inline=function(x){paste0("<span style=\"color: #0000FF;\">",  x,"</span>")})````r pi`

The only issue with this is that it doesn't work if I change to html_notebook in the YAML header and thus use the "Preview" button in the RStudio IDE. For external reasons, it's important for us to have the output type as html_notebook. Anyone know how we might modify this to get it to work with html_notebook?


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images