2

I am getting this error upon running the following code and do not know how to fix it. I have svglite installed but when I run library(svglite) I get the same error:

Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/gdtools/libs/gdtools.so': dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/gdtools/libs/gdtools.so, 6): Library not loaded: /opt/X11/lib/libcairo.2.dylib Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/gdtools/libs/gdtools.so Reason: image not found

x = c(1,2,3,4)
y = c(1,2,3,4)

p <- ggplot(data = data.frame(x=x,y=y), aes(x = x, y = y))  + 
geom_line() + 


ggsave(filename = "ROC_plot_6x4.svg", plot = p, device = "svg", 
   width = 6, height = 4, units = "in")

library(svglite)
Tung
  • 26,371
  • 7
  • 91
  • 115
Jonathan Levy
  • 41
  • 1
  • 6
  • Have you looked at e.g. [this question/answers](https://stackoverflow.com/questions/21333097/got-message-unable-to-load-shared-object-stats-so-when-r-starts)? – Roman Luštrik May 20 '18 at 20:54
  • The *cairo* library is a system requirement for the `gdtools` package. Do you have it installed, e.g. via homebrew? – Ralf Stubner May 20 '18 at 21:09
  • Thanks for the response. I really know nothing of homebrew. I just tried installing it and nothing happened when I typed /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) into the terminal as directed. I'm on a mac OS10.12.6, btw. It appears I don't have that library in my version of R 3.5. I looked at the link Roman left and did not find it helpful. – Jonathan Levy May 20 '18 at 22:01
  • Scratch that, I actually went to Roman's link again and managed to put about 10 folders in the proper library by hand and the problem is solved. Sorry, Roman, you were correct. – Jonathan Levy May 20 '18 at 23:38

1 Answers1

1

Quick Fix: Install XQuartz

I ran into this trying to use the library ggiraph, which has a gdtools dependency. The Mac OS X binaries for both gdtools and systemfonts (one of its dependencies) have hardcoded links to X11, which corresponds to a default XQuartz installation. So, if you don't have any of these libraries and/or just want to be able to download the binaries with no fuss, then install XQuartz.

FWIW, CRAN's download page for R (OS X) does mention that some packages require X11:

Note: the use of X11 (including tcltk) requires XQuartz to be installed since it is no longer part of OS X. Always re-install XQuartz when upgrading your macOS to a new major version.

merv
  • 67,214
  • 13
  • 180
  • 245