9

I'm trying to install "XML" package in r, but an error occurs.
Please tell me what's wrong.

OS: OS X 10.11.6
R version: 3.3.2
The error message when executing "install.packages("XML") is the following.

* installing *source* package ‘XML’ ...
** package ‘XML’ successfully unpacked and MD5 sums checked
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for sed... /usr/bin/sed
checking for pkg-config... /usr/local/bin/pkg-config
checking for xml2-config... /usr/bin/xml2-config
USE_XML2 = yes
SED_EXTENDED_ARG: -E
Minor 9, Patch 2 for 2.9.2
Located parser file -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2/parser.h
Checking for 1.8:  -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2
Using libxml2.*
checking for gzopen in -lz... yes
checking for xmlParseFile in -lxml2... no
checking for xmlParseFile in -lxml... no
configure: error: "libxml not found"
ERROR: configuration failed for package ‘XML’

And I set LIBXML_INCDIR=/usr/local/Cellar/libxml2/2.9.4, and tried again.
Then another error occurs.

* installing *source* package ‘XML’ ...
** package ‘XML’ successfully unpacked and MD5 sums checked
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for sed... /usr/bin/sed
checking for pkg-config... /usr/local/bin/pkg-config
Checking directory of LIBXML_INCDIR
You specified LIBXML_INCDIR, but we couldn't find parser.h
Please specify it correctly and re-run the INSTALL'ation.
ERROR: configuration failed for package ‘XML’

Also tried with LIBXML_INCDIR=/usr/local/Cellar/libxml2/2.9.4/include
The result was same as above.

Regards

Ken
  • 123
  • 1
  • 10
  • 1
    It looks like the issue is not with `LIBXML_INCDIR`, but that a shared library file is not being found. In the first attempt `parser.h` is found when you left this unspecified: `Located parser file -I/Applications/Xcode.app/[...]`. – nrussell Nov 18 '16 at 17:33
  • 1
    Thank you for your comment. I'm guessing LIBXML_INCDIR is not a problem in the first attempt, but I don't have any idea about the solution, so I gave it a try just because LIBXML_INCDIR is said to be related to libxml on some web pages. Please excuse my lack of explanation. – Ken Nov 18 '16 at 18:55
  • 1
    Try running `brew link libxml2` from a terminal and then reinstalling the R package. – nrussell Nov 18 '16 at 18:56
  • 1
    Thank you very much. "brew link libxml2 --force" worked. – Ken Nov 18 '16 at 19:27
  • @Ken I am having the same problem but `brew link libxml2 --force` is not working for me. Where are you specifying `LIBXML_INCDIR=/usr/local/Cellar/libxml2/2.9.4/include`? Thanks for any assistance here. – Conrad Nov 27 '17 at 15:31
  • @Conrad Sorry I don't remember, but maybe the place I specified LIBXML_INCDIR is in '.bash_profile'. But as you can see, it didn't work for me. – Ken Nov 29 '17 at 20:35
  • @Ken sorry I forgot to update things here - I submitted my own question and promptly discovered the answer! https://stackoverflow.com/questions/47540782/cannot-install-xml-package-in-r-rstudio – Conrad Nov 29 '17 at 21:01

3 Answers3

10

This worked for me in Mac OS X 10.11:

In the Terminal:

type xml2-config
xml2-config is /opt/local/bin/xml2-config

In R:

Sys.setenv(XML_CONFIG="/opt/local/bin/xml2-config")
Freeman
  • 5,810
  • 3
  • 47
  • 48
  • 1
    I had a problem on Mac OS X 10.12 and I used Homebrew. My xml2-config was at `/usr/local/Cellar/libxml2/2.9.7/bin/xml2-config` – Roman Zenka Feb 21 '18 at 02:54
1

Rather than forcing the linking of the libxml2 version from homebrew, you can edit the file $HOME/.R/Makevars to include:

CC=clang -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk CXX=clang++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk

Edit the SDK version (i.e. MacOSX10.13 in above example) to match your installed version. See https://forums.developer.apple.com/thread/87829 for (minimal) explanation.

jvd10
  • 1,826
  • 17
  • 17
  • under catalina, this became: ``` CC=clang -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk CXX=clang++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk``` and fixed my issue which was not being able to upgrade the R package XML because of the miniconda xml-config taking precedence on the system copy – splaisan Oct 28 '22 at 13:03
0

For libxml2 install by Homebrew, I used:

export XML_CONFIG=/usr/local/Cellar//libxml2/2.9.10_1/bin/xml2-config 

and it worked.

user890739
  • 702
  • 1
  • 13
  • 33