Ligature fonts for R
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Ligature fonts are fonts which sometimes map multiple characters to a single glyph, either for readability or just because it looks neat. Importantly, this only affects the rendering of the text with said font, while the distinct characters remain in the source.
Maybe ligatures are an interesting topic in themselves if you’re into typography, but it’s the relatively modern monospaced variants which are significantly more useful in the context of R programming.
Two of the most popular fonts in this category are:
- Fira Code — an extension of Fira Mono which really goes all out providing a wide range of ligatures for obscure Haskell operators, as well as the more standard set which will be used when writing R
- Hasklig — a fork of Source Code Pro (in my opinion a nicer base font) which is more conservative with the ligatures it introduces
Here’s some code to try out with these ligature fonts, first rendered via bog-standard monospace font:
library(magrittr) library(tidyverse) filtered_storms <- dplyr::storms %>% filter(category == 5, year >= 2000) %>% unite("date", year:day, sep = "-") %>% group_by(name) %>% filter(pressure == max(pressure)) %>% mutate(date = as.Date(date)) %>% arrange(desc(date)) %>% ungroup() %T>% print()
Here’s the same code rendered with Hasklig:
Some of the glyphs on show here are:
- A single arrow glyph for less-than hyphen (<-)
- Altered spacing around two colons (::)
- Joined up double-equals
Fira Code takes this a bit further and also converts >= to a single glyph:
In my opinion these fonts are a nice and clear way of reading and writing R. In particular the single arrow glyph harks back to the APL keyboards with real arrow keys, for which our modern two-character <- is a poor substitute.
One downside could be a bit of confusion when showing your IDE to someone else, or maybe writing slightly longer lines than it appears, but personally I’m a fan and my RStudio is now in Hasklig.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.