include cairo R on a mac include cairo R on a mac r r

include cairo R on a mac


You should download X11 for Mac, which is called XQuartz. It doesn't ship with OS X any more, so you have to download it separately from: https://www.xquartz.org/


For anyone for whom installing XQuartz did not fix the problem:

Check the part of the error message that begins with "Library not loaded: ...". E.g., in the user's question, the error message contains this line:

dlopen(/Library/Frameworks/R.framework/Versions/3.3/Resources/library/Cairo/libs/Cairo.so, 6): Library not loaded: /opt/X11/lib/libXrender.1.dylib

Note this part:

Library not loaded: /opt/X11/lib/libXrender.1.dylib

That is the part that clues us in about XQuartz.

In my case, however, it specified that libjpeg was not loaded, like this:

Error: package or namespace load failed for ‘Cairo’: .onLoad failed in loadNamespace() for 'Cairo', details:  call: dyn.load(file, DLLpath = DLLpath, ...)  error: unable to load shared object '/usr/local/lib/R/3.5/site-library/Cairo/libs/Cairo.so':  dlopen(/usr/local/lib/R/3.5/site-library/Cairo/libs/Cairo.so, 6): Library not loaded: /usr/local/opt/jpeg/lib/libjpeg.9.dylib  Referenced from: /usr/local/lib/R/3.5/site-library/Cairo/libs/Cairo.so  Reason: image not foundError: loading failed

Note this part:

Library not loaded: /usr/local/opt/jpeg/lib/libjpeg.9.dylib

To fix this, I had to run

brew unlink libjpeg; brew reinstall libjpeg

to get it working. I then had to do the same thing for libtiff:

brew unlink libtiff; brew reinstall libtiff

After fixing both of those libraries, running install.packages("Cairo") worked.