MetaboAnalystR - Installation issue (Cairo missing in MacOS)

Hi all,
I am running into trouble downloading the MetaboAnalystR package, having run into a few errors along the way that I have attempted to correct. I first attempted to use the download instructions on the MetaboAnalystR website, to no avail. I then found a post on BioStars linked here with another way to download the package, but have continued to run into issues. My code is as follows below:

if (!requireNamespace("BiocManager", quietly = TRUE))
  install.packages("BiocManager")

BiocManager::install("BiocVersion", force = TRUE)

BiocManager::install(c("impute","pcaMethods","globaltest","GlobalAncova","Rgraphviz","preprocessCore",
                       "genefilter","sva","limma","KEGGgraph","siggenes","BiocParallel","MSnbase",
                       "multtest","RBGL","edgeR","fgsea", "ctc"), force = TRUE)

install.packages("devtools")
library(devtools)

# install Rtools from https://cran.r-project.org/bin/windows/Rtools/ (Windows 64 bit)
## Define file path for Rtools
writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")
## Restart r
Sys.which("make")
find_rtools()

install.packages(c("pls","Rserve","ellipse","scatterplot3d","Cairo","randomForest","caTools","e1071","som",
                   "RJSONIO","ROCR","pheatmap","pROC","fitdistrplus","lars","Hmisc","caret","crmn"))

install.packages("igraph")
library("igraph") 

devtools::install_version('mnormt', version = "1.5-7", repos="http://cran.rstudio.com")

library("quantreg") 

install.packages(c("impute", "pcaMethods", "globaltest","GlobalAncova", 
                   "Rgraphviz", "preprocessCore", "genefilter", "SSPA", 
                   "sva", "limma", "KEGGgraph", "siggenes","BiocParallel", 
                   "MSnbase", "multtest","RBGL","edgeR","fgsea","httr","qs",
                   "metap","entropy","rsm","Rcpp","gplots","reshape","spls"))


package_dependencies <-(c("impute","pcaMethods","globaltest","GlobalAncova","Rgraphviz","preprocessCore",
                          "genefilter","sva","limma","KEGGgraph","siggenes","BiocParallel","MSnbase",
                          "multtest","RBGL","edgeR","fgsea","httr","pls","Rserve","ellipse","scatterplot3d","Cairo","randomForest","caTools","e1071","som",
                          "RJSONIO","ROCR","pheatmap","pROC","fitdistrplus","lars","Hmisc","caret","crmn", "impute", "pcaMethods", "globaltest","GlobalAncova", 
                          "Rgraphviz", "preprocessCore", "genefilter", "SSPA", 
                          "sva", "limma", "KEGGgraph", "siggenes","BiocParallel", 
                          "MSnbase", "multtest","RBGL","edgeR","fgsea","httr","qs",
                          "metap","entropy","rsm","Rcpp","gplots","reshape","spls"))


lapply(package_dependencies, require, character.only = TRUE)

devtools::install_github("xia-lab/MetaboAnalystR", build = TRUE, build_vignettes = TRUE, build_manual =T)

Currently, the error preventing the download of the package is this:

ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin18/8.2.0'
installing to /Library/Frameworks/R.framework/Versions/4.2/Resources/library/00LOCK-MetaboAnalystR/00new/MetaboAnalystR/libs
** R
** inst
** byte-compile and prepare package for lazy loading
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/4.2/Resources/library/Cairo/libs/Cairo.so':
  dlopen(/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Cairo/libs/Cairo.so, 0x0006): Library not loaded: /opt/X11/lib/libXrender.1.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/4.2/Resources/library/Cairo/libs/Cairo.so
  Reason: tried: '/opt/X11/lib/libXrender.1.dylib' (no such file), '/Library/Frameworks/R.framework/Resources/lib/libXrender.1.dylib' (no such file), '/Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home/jre/lib/server/libXrender.1.dylib' (no such file)
Execution halted
ERROR: lazy loading failed for package ‘MetaboAnalystR’
* removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/MetaboAnalystR’
Warning message:
In i.p(...) :
  installation of package ‘/var/folders/57/_67sn0dn0cx_5gdz2k4q716w0000gn/T//RtmpyNA0hI/file23c22cfadb0f/MetaboAnalystR_3.2.0.tar.gz’ had non-zero exit status

My initial searches for a solution have led me here, where the issue with gfortran is solved by downloading versions of gfortran from the past, but from the R website, it seems those solutions are only compatible with versions of R prior to 4.0.0.

I am currently using R 4.2.1, RStudio 2022.07.1, and gfortran version 8.2.0.
Any ideas on how to solve this issue?

Hi jsung,

You’ll notice that the message for gfortran is only a warning, while there is a separate error message for the ‘Cairo’ package. I would focus on trying to get the ‘Cairo’ package installed first, and then see if you can get the overall R package to load. It’s likely that the gfortran warning is not critical.

Hi Jsung,

Thanks for your post. According to your error message, as Jess mentioned above, you have to make sure the dependent R package “Cairo” has been installed successfully. But clearly, there is an error when your XOS was trying to install it. That is due to the missing of your OS dependency, please make sure the “X11” and “cairo” has been configured well.
Try this command to install “cairo” into your XOS:

sudo port install cairo

Admin privilege is required for this action. If you encounter more issues, please remove this one-by-one by installing/configuring corresponding packages.

:slight_smile:

Bests,
Zhiqiang

That worked, thank you both so much!

Hi,

I am running into the same cairo error on windows system while using RStudio. Any help will be appreciated.

I have successfully installed cairo package on RStudio but it seems like more of OS level error.

Error: package or namespace load failed for ‘MetaboAnalystR’:
.onLoad failed in loadNamespace() for ‘Cairo’, details:
call: library.dynam(“Cairo”, pkgname, libname)
error: DLL ‘Cairo’ not found: maybe not installed for this architecture?
Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for ‘i386’