XML for R 4.0.5

Hi there,
I am trying to install the package XML for R 4.0.5.

When I try installing it internally from R with the function install.packages(), I get the following error:

> install.packages("XML")
Retrieving 'https://cloud.r-project.org/src/contrib/XML_3.99-0.8.tar.gz' ...
        OK [file is up to date]
Installing XML [3.99-0.8] ...
Error installing package 'XML':

* installing to library ‘/home/giuliocentorame/Repositories/xxxxxx/renv/staging/1’
* installing *source* package ‘XML’ ...
** package ‘XML’ successfully unpacked and MD5 sums checked
** using staged installation
  Cleaning up after installing the XML package
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking how to run the C preprocessor... gcc -E
checking for sed... /usr/bin/sed
checking for pkg-config... /usr/bin/pkg-config
checking for xml2-config... /home/giuliocentorame/anaconda3/bin/xml2-config
USE_XML2 = yes
Minor 9, Patch 10 for 2.9.10
Located parser file -I/home/giuliocentorame/anaconda3/include/libxml2 -I/home/giuliocentorame/anaconda3/include/parser.h
Checking for 1.8:  -I/home/giuliocentorame/anaconda3/include/libxml2 -I/home/giuliocentorame/anaconda3/include
Using libxml2.*
checking for gzopen in -lz... yes
checking for xmlParseFile in -lxml2... yes
You are trying to use a version 2.* edition of libxml
but an incompatible library. The header files and library seem to be
mismatched. If you have specified LIBXML_INCDIR, make certain to also
specify an appropriate LIBXML_LIBDIR if the libxml2 library is not in the default
ERROR: configuration failed for package ‘XML’
* removing ‘/home/giuliocentorame/Repositories/xxxxxx/renv/staging/1/XML’
Error: install of package 'XML' failed [error code 1]
Traceback (most recent calls last):
12: install.packages("XML")
11: install(pkgs)
10: renv_install_impl(records)
 9: renv_install_staged(records)
 8: renv_install_default(records)
 7: handler(package, renv_install_package(record))
 6: renv_install_package(record)
 5: withCallingHandlers(renv_install_package_impl(record), error = function(e) {
 4: renv_install_package_impl(record)
 3: r_cmd_install(package, path)
 2: r_exec_error(package, output, "install", status)
 1: stop(error

I get the same error if I use R with Anaconda. Anaconda does have an XML version built-in, but it’s for R 3.6.x (and I can’t downgrade it due to the entirety of my projects being on R 4.x.x).

Unfortunately, I have no idea on how to set up those variables and what with. I suspect it’s a libxml version conflict just like the one here, but I have no idea on how to fix it.

I tried installing it from dnf (even though it isn’t really good practice), but R doesn’t recognise it anyway.

Would you be able to help me find a fix for it? Thanks a lot


Are you using sudo?
If not then try it.

Hmmm. Looks like you’re using the conda version of libxml2 to build against, but possibly the system version of the actual library.

I take it you have R installed mostly or entirely via conda?

The “easy” Fedora answer is dnf install R R-XML, but that doesn’t sound like it’s going to help you.



What on? Do you mean sudo R and then install.packages("XML")?

My R is installed through Fedora, I can actually ditch conda altogether for now and try to fix the integration with conda later. The only thing that I really need is the integration with renv for the time being

Okay, so, I think that mixing is probably some of the problem. Does the R-XML package from the Fedora repos work for you?

I can install it, but it does not change anything out of the box when I am going to install the package through R

Edit: sorry, this makes no sense. I meant that R does not recognise it as installed (I’d assume because it’s looking at renv’s folder instead of the user folder)

Okay, so, I’m not getting something here. Why install the package internally from R when there’s already an RPM package for it?

This is a legit question, not a rhetorical one – I’m not super-familiar with the R ecosystem. What are the shortcomings of using the system package?

1 Like

Reproducibility. The most important shortcoming of using R is the compatibility between modules in the R ecosystem: there are something like 18k packages at the moment in CRAN (the official repo), upgraded fairly frequently and with loads of dependencies, so even small changes in functions have consequences in the entire ecosystem and break a lot of code or make it nonreproducible. There are no Linux binaries available too, so everything is compiled from source on those systems.
This probably does not affect XML (which is a fairly stable package), but for some packages with a faster development cycle, it’s an actual issue.

The main ways to overcome this shortcoming in R are either to use a fixed release system for all of your packages, tied to the R version (e.g., in Bioconductor or the Anaconda repo), or to use renv (used to be packrat), which installs your packages in the project library and pins them to a specific version–so if you have to run the code again or transfer it to another machine it will run it installing the specific package version you’ve provided (and no conflicts with the most recent one you might have on your user library). Also, to publish on CRAN the package has to undergo some pretty mental checks (and they get unpublished very quickly), so you are usually confident that the most recent versions on CRAN won’t cause too many package dependency issues.
Distro packages tend to get outdated pretty quickly, so it can get messy with multiple sources and when adding new packages you are often forced to use everything at the most recent CRAN version, to avoid incompatibility issues (with the important exception of the R version itself, which is usually made so that things don’t break too badly between subversions).

As an example, I am currently using an average of 6-7 packages (aka “”“libraries”"") beyond base R per script on my current project, 2 from a Github repo (tied to the commits), 4 from the official repos (tied to the CRAN release version), and 1-2 built-ins (tied to the R version). It would be really inconvenient to solve possible incompatibility issues with distro-specific package versions.

Hope this makes it clearer


Ah, yeah, I get it. My suggestion would be to do all of this in a container (possibly using toolbx), with R only installed via Conda.

1 Like

The problem I am currently having is that I would rather not use the Anaconda version of R for the current project, since it’s stuck at 3.6 and I need some changes that are present on 4.x.x. Do you think that removing it temporarily altogether would fix the issue? I would probably then proceed to containerize it all as soon as this is done

Hmmm. I am guessing that you. might be able to address this by setting LIBXML_INCDIRto the system include path?

So you mean /bin/xml2-config?

Yeah, that should probably do it. Not sure exactly what value to pass to R’s package manager to tell it that, but surely there’s a way.

1 Like

Hi @fbackstab,
Have you managed to solve the problem? I’m running precisely into the same issue, integration with renv for the package XML.

Edit: I noticed that line in @fbackstab’s first post:

It seems that could explains why the error is also present using his Anaconda’s R, both of them use xml2-config from anaconda.

I have the same issue as well:
checking for xml2-config... /home/etheimer/miniconda3/bin/xml2-config

So the question becomes : why is the XML package installation not using the xml2-config in /usr/bin?
When I execute which xml2-config, I get /usr/bin/xml2-config. So the path seems correct, yet XML does not respect it? Any idea as to why?

Edit 2: I have modified the configure file after having downloaded the tar archive. Adding withval=$with_xml_config; XML_CONFIG=/usr/bin/xml2-config line 2387 and PKG_CONFIG=/usr/bin/pkg-config line 3679 solves the problem (if in a bit of a hacky way). However, this fix does not function with renv, as renv requires the packages to be dowloaded from known sources.

1 Like

Hi there,
In any case someone is still struggling with this issue.
I solved the issue by having the following settings in R (installed in ubuntu cmd NOT via CONDA)

1.) Sys.setenv(XML_CONFIG=“/export/home/mrogoopa/comp/usr/bin/xml2-config”)

2.) install.packages(‘/export/home/mrogoopa/tmp/packages/XML_3.99-0.10.tar.gz’, configure.args=c(‘–with-libxml2=/export/home/mrogoopa/comp/usr/bin/xml2-config LIBXML_LIBDIR=-L/export/home/mrogoopa/comp/usr/lib/x86_64-linux-gnu LIBXML_INCDIR=/export/home/mrogoopa/comp/usr/include/libxml2’))

As you can see I have set the INCDIR not to point to the libxml2/libxml folder rather libxml2 folder. I guess that is one of the issues. Ensure that your libxml2.pc is also properly configured as follows (Change the prefix path)


Name: libXML
Version: 2.9.10
Description: libXML library version2.
Libs: -L${libdir} -lxml2 -lz
Libs.private: -licui18n -licuuc -licudata -lz -llzma -lm
Cflags: -I${includedir}/libxml2

Good luck!