Installing the XML
R package can be tricky if you don't have the right systems depdencies.
If these are set up right, you'll get a zero-exit status when trying to install XML
from source.
The system dependency libxml2
is the main one you need to worry about.
Here are a variety of solutions for installing this.
You can use apt-get
(comes preinstalled on most Linux-based platforms) to install libxml2
sudo apt-get update
sudo apt-get install libxml2 libxml2-dev
Additionally, you can also install xml from the command line instead of within R:
sudo apt-get install r-cran-xml
Alternatively, you can use brew
(comes preinstalled on most Mac-based platforms) instead of apt-get
.
If you don't already have brew
installed, set that up first.
Then install libxml2
brew install libxml2
You can also use yum
instead.
sudo yum install libxml2
If you're working within a conda
environment, you can do the following:
conda activate <env_name>
conda install -c anaconda libxml2
You can also just install XML
R package directly with conda
. In theory, this should automatically install all the necessary system dependencies as well.
conda install -c conda-forge r-xml
In some environments, you may also need to export the xml2-config
file.
This is the case for GitHub Actions servers.
echo "XML_CONFIG=/usr/local/opt/libxml2/bin/xml2-config" >> $GITHUB_ENV
Now you can install the XML
R package.
Within R:
install.packages("XML")
Be sure to restart your R session to ensure the new installation gets recognized
(the CMD
+SHIFT
+0
keystroke on Mac).
This solution is already implemented within rworkflows
GitHub action (here)
so that users don't have to worry about this troubleshooting.