rmacosghostscriptapple-m1extrafont

GhostScript was not found with extrafont


I'm using an M1, Big Sur Macbook. I need to embed the fonts of a number of pdfs that include plots from ggplot2.

However, when I run the embed_fonts() function, it returns the following error message: GhostScript was not found

With Homebrew, I installed Ghostscript. I have also reinstalled extrafont and extrafontdb, restarted RStudio, and then run font_import() and loadfonts() again. None of this solves the error message.

Have you experienced this problem? I wonder if it's because of the change to the M1's Apple Silicon?

I have also switched from using bash to zsh in my terminal. Could that have affected this?

A reprex:

library(ggplot2)
library(extrafont)

(plot <- ggplot(cars, aes(x = speed, y = dist)) +
    geom_point())

ggsave("test_plot.pdf", plot)

embed_fonts(file = "test_plot.pdf", outfile = "test_plot_embedded.pdf")

I found the following two answers that seem related, but I'm unsure how to implement them:

How to fix "Unable to find GhostScript executable to run checks on size reduction" error upon package check in R?

R does not recognize GhostScript to embed eps plots


Solution

  • My issue was solved when I installed Ghostscript directly https://pages.uoregon.edu/koch/ (Ghostscript 9.54.0)

    It appears there was, at least on my end, an issue using homebrew install ghostscript. When I ran that in Terminal, everything appeared to be fine. No error messages.