include cairo R on a mac
Asked Answered
A

2

18

I'm trying to use 'Cairo' package in Rstudio, using the command install.packages('Cairo') and it goes through with no problem. I get this message-

The downloaded binary packages are in
/var/folders/xn/c1nj85gx62b89876s15sbv9h0000gn/T//RtmpK9JM0l/downloaded_packages 

The package appears in the packages list, but when I try to include the package using library(Cairo) or library('Cairo') I get this error mesage-

Error : .onLoad failed in loadNamespace() for 'Cairo', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.3/Resources/library/Cairo/libs/Cairo.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.3/Resources/library/Cairo/libs/Cairo.so, 6): Library not loaded: /opt/X11/lib/libXrender.1.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/Cairo/libs/Cairo.so
  Reason: image not found
Error: package or namespace load failed for ‘Cairo’

sessionInfo()

R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)

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

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

other attached packages:
[1] GenomicRanges_1.24.2 GenomeInfoDb_1.8.3   IRanges_2.6.1       
[4] S4Vectors_0.10.2     ggbio_1.20.2         BiocGenerics_0.18.0 
[7] ggplot2_2.1.0        BiocInstaller_1.22.3 shiny_0.13.2        

I'm not sure why is this happening, any help? Thanks!

Atlantic answered 15/8, 2016 at 9:19 Comment(6)
And you have quartz installed as your main X11 platform? If not, then download, install it and restart your machine. Hopefully, that'll help.Eavesdrop
Thanks! I don't, is there a reason that 'Cairo' needs quartz? because I never had this problem when I installed packagesAtlantic
I believe it has always needed it. It's just that on previous Mac version an equivalent of an X11 platform was being shipped with the operating systems. However, that's not been the case with latest releases. That's why you have to get it yourself. Have you been able to load the package now?Eavesdrop
I'm not next to my computer now, I'll it when I'll get back home.Atlantic
Thank you! worked like magic!Atlantic
I'll just add that the reason that I had a problem only with Cairo and not with other packages is because it's a package that deals with graphics, and "XQuartz is required component that allows cross-platform applications, many of which were not specifically designed for OS X, to run on it."WikipediaAtlantic
D
30

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/

Decrial answered 15/8, 2016 at 21:56 Comment(7)
Thank you! that was indeed the problem.Atlantic
If is solved your problem vote it as a solution so others can find it easilyDecrial
How do I do this? With the gray up arrow? (I tried, but got some note that I can't yet vote because I'm new here..)Atlantic
I think it is that gray "tick" symbol right below that arrowsDecrial
I've removed and reinstalled XQuartz, but to no avail. I'm on macOS High Sierra with R 3.4.2 installed via brew. I'm trying to install 'scde' via Bioconductor. Do you know an alternative solution?Tamartamara
@SanderW.vanderLaan You've probably moved past this issue, but I posted an answer about fixing it when XQuartz is already installed that may be relevant to you below.Anatropous
@ChrisMiddleton: Thanks!Tamartamara
A
3

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 found
Error: 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.

Anatropous answered 5/3, 2019 at 17:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.