wch / extrafont

Tools for using fonts in R graphics
315 stars 48 forks source link

Unrecoverable error with Ghostscript 9.16 Mac OSX? #53

Closed dbarneche closed 7 years ago

dbarneche commented 7 years ago

Hello,

I recently started having an issue with embedding fonts via extrafont::embed_fonts, and I have no idea why. I have the following functions that I use to produce pdfs with CM Roman font:

toDev  <-  function (expr, dev, filename, ..., verbose = TRUE) {
    if (verbose) {
        cat(sprintf('Creating %s\\n', filename))
    }
    dev(filename, family = 'CM Roman', ...)
    on.exit(dev.off())
    eval.parent(substitute(expr))
}

toPdf  <-  function (expr, filename, ...) {
    toDev(expr, pdf, filename, ...)
}

If I run

library(extrafont)
library(fontcm)
extrafont::loadfonts(quiet = TRUE)

myPlot  <-  function () {
    plot(0, 0)  
}

toPdf(myPlot(), '~/Desktop/myPLot.pdf', width = 7, height = 7)
extrafont::embed_fonts('~/Desktop/myPLot.pdf')

I get this error:

Error: /undefinedfilename in (~/Desktop/myPLot.pdf)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push
Dictionary stack:
   --dict:1184/1684(ro)(G)--   --dict:0/20(G)--   --dict:78/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
GPL Ghostscript 9.16: Unrecoverable error, exit code 1
Error in gettextf("status %d in running command '%s'", ret, cmd) : 
  object 'cmd' not found

I get the same error if I use instead

grDevices::embedFonts('~/Desktop/myPLot.pdf')

This has never happened to me before, and I have been using this workflow with extrafont::embed_fonts for years now. Any ideas of what could be causing this? Here are my sessionInfo() specs:

R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] fontcm_1.1     extrafont_0.17

loaded via a namespace (and not attached):
[1] compiler_3.4.1  tools_3.4.1     extrafontdb_1.0 Rttf2pt1_1.3.4 

Thanks!

dbarneche commented 7 years ago

I solved it after reinstalling extrafontdb and then running:

library(extrafont)
library(fontcm)
font_import()
font_install('fontcm')

Thanks anyway!