Syntax Highlighting of R-Code using Blogdown

As I’m moving this blog from wordpress to blogdown (also see the book about blogdown) I was wonderung how I can get some nice syntax highlighting of the embedded R-code.

The first impression was quite sobering. I used the default .Rmd page type and I got not much highlighting. It was better than that I got at Medium with base functionality. But it’s not quite what I wanted.

But there are two other file types in blogdown.

Blogdown file types

.md is for simple markdown-pages without any R-code. But the other one .Rmarkdown seems to be more promising.

Using git as package manager for R

Okay, the title may be a little misleading. But it addresses the problem I have.

I’m running many different R projects in production. So they must run in a reproductive way and I can’t afford that the programs break if a package update is installed.

dplyr for programming

When someone asks me what’s the main advantage of R over python I almost always answer: “It’s dplyr! The way you can handle data.frames is a dream.”

Pythonista: “But pandas has also Data.Frames. They are built to resemble their counterparts in R.”

Me: “That’s true. But they manage the functionality of plain R. Actually R has made several steps ahead with dplyr.”

But dplyr is built mainly for interactive data exploration. So it’s very easy to select, mutate, group and summarize your data.frame (or tibble). The reason is non-standard evaluation (NSE) (See more in Hadley Wickham’s book Advanced R. NSE occures when you use a column-name without any quoting.

But when it’s up to programming it get’s a little more complicated.

So let’s look at an example: