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?