knitr unable to load showtext / sysfonts

Viewed 948

I've been using knitr along with the showtext library to produce HTML files that use some Google fonts. It has worked fine until I upgraded R to 3.4. When I knit the document now, I get the following error:

Error: package 'sysfonts' could not be loaded Execution halted

This is reproducible by knitting:

---
title: "test"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(showtext)
```

It runs fine without the library(showtext).

Then, when I try running it with library(sysfonts) using the same template:

---
title: "test"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(sysfonts)
```

I get this error:

Error: package or namespace load failed for 'sysfonts': .onLoad failed in loadNamespace() for 'sysfonts', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object '~/Library/R/3.4/library/sysfonts/libs/sysfonts.so': dlopen(~/Library/R/3.4/library/sysfonts/libs/sysfonts.so, 6): Library not loaded: /opt/X11/lib/libfreetype.6.dylib Reference from: ~/Library/R/3.4/library/sysfonts/libs/sysfonts.so Reason: image not found

It seems like an issue with the sysfonts library. However, I can load showtext and sysfonts just fine from the console. So I don't know if this is a sysfonts issue or a knitr issue. I'm running El Capitan 10.6 and again, recently upgraded R to 3.4. I tried downgrading back to 3.3, but still produced the same error.

1 Answers

A late reply, which yet might come useful to others (if working on a Mac):

1) remove all relevant R-packages

remove.packages("sysfonts")
remove.packages("showtext")

2) install XQuartz

3) reinstall and load all packages again

install.packages("sysfonts")
install.packages("showtext")

This solution provided by tcarnus on GitHub solved the issue for me.

Related