2

Trying to install R package ggiraph on my Mac OS X I ran into a problem with dependency xml2.

This seems to be a fairly common problem for users of this and other packages so after reading threads here and elsewhere I confirmed the following:

  • RStudio, R, and all its packages are up do date
  • libxml2 is installed in developer version, using homebrew
  • I have copied libxml-2.0.pc from homebrew folder to /usr/local/lib/pkgconfig/
  • I have added /usr/local/lib/pkgconfig/ to PATH and PKG_CONFIG_PATH

I still get the below error message during installation. Thankful for help!

> install.packages("ggiraph")
Installing package into ‘/usr/local/lib/R/3.5/site-library’
(as ‘lib’ is unspecified)
also installing the dependency ‘xml2’

trying URL 'https://cran.rstudio.com/src/contrib/xml2_1.2.0.tar.gz'
Content type 'application/x-gzip' length 251614 bytes (245 KB)
==================================================
downloaded 245 KB

trying URL 'https://cran.rstudio.com/src/contrib/ggiraph_0.6.0.tar.gz'
Content type 'application/x-gzip' length 208710 bytes (203 KB)
==================================================
downloaded 203 KB

* installing *source* package ‘xml2’ ...
** package ‘xml2’ successfully unpacked and MD5 sums checked
Found pkg-config cflags and libs!
Using PKG_CFLAGS=-I/usr/include/libxml2
Using PKG_LIBS=-L/usr/lib -lxml2 -lz -lpthread -licucore -lm
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libxml-2.0 was not found. Try installing:
 * deb: libxml2-dev (Debian, Ubuntu, etc)
 * rpm: libxml2-devel (Fedora, CentOS, RHEL)
 * csw: libxml2_dev (Solaris)
If libxml-2.0 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libxml-2.0.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------
ERROR: configuration failed for package ‘xml2’
* removing ‘/usr/local/lib/R/3.5/site-library/xml2’
Warning in install.packages :
  installation of package ‘xml2’ had non-zero exit status
ERROR: dependency ‘xml2’ is not available for package ‘ggiraph’
* removing ‘/usr/local/lib/R/3.5/site-library/ggiraph’
Warning in install.packages :
  installation of package ‘ggiraph’ had non-zero exit status
pengzell
  • 33
  • 4

1 Answers1

0

This is a recurrent problem I have on macOS with Homebrew and libxml2. The includes of libxml2 are located in a subdirectory /path/to/includes/libxml2/libxml/ which can't be found by compilers.

I successfully installed xml2 in R doing two things:

  1. Create symlink [...]/include/libxml pointing to [...]/include/libxml2/libxml
  2. Add the include folder path to INCLUDE_DIR

Do point 1 in a terminal. Although filepath may be different on your installation, the shell command on my mac was:

Bash > ln -s /usr/local/Cellar/libxml2/2.9.9_2/include/libxml2/libxml /usr/local/Cellar/libxml2/2.9.9_2/include/libxml`

Do point 2 in RStudio's R Terminal. The command on my mac was:

R > Sys.setenv(INCLUDE_DIR = paste("/usr/local/Cellar/libxml2/2.9.9_2/include", Sys.getenv("INCLUDE_DIR"), sep = ":"))`

Then install xml2 and ultimately ggiraph:

R > install.packages(c("xml2", "ggiraph"))
Slagt
  • 589
  • 2
  • 10