Skip to content

Instantly share code, notes, and snippets.

@bschilder
Last active November 5, 2023 14:32
Show Gist options
  • Save bschilder/4ca6857215d96724d12488b6805233c7 to your computer and use it in GitHub Desktop.
Save bschilder/4ca6857215d96724d12488b6805233c7 to your computer and use it in GitHub Desktop.

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.

1. Install libxml2

With apt-get:

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

With brew

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

With yum

You can also use yum instead.

sudo yum install libxml2

With conda

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

2. Set up libxml2 path

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

3. Install XML

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).

rworkflows

This solution is already implemented within rworkflows GitHub action (here) so that users don't have to worry about this troubleshooting.

Related issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment