2

I tried to install two packages in R Studio: tidyverse and quantmod. However both give me errors and I can't understand why (googling doesn't help to understand the problem).

For tidy verse I get:

> install.packages("tidyverse")
also installing the dependency ‘xml2’


  There are binary versions available but the source versions are later:
          binary source needs_compilation
xml2       1.1.1  1.2.0              TRUE
tidyverse  1.1.1  1.2.1             FALSE

Do you want to install from sources the package which needs compilation?
y/n: y
installing the source packages ‘xml2’, ‘tidyverse’

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/tidyverse_1.2.1.tar.gz'
Content type 'application/x-gzip' length 61647 bytes (60 KB)
==================================================
downloaded 60 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 ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/xml2’
Warning in install.packages :
  installation of package ‘xml2’ had non-zero exit status
ERROR: dependency ‘xml2’ is not available for package ‘tidyverse’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/tidyverse’
Warning in install.packages :
  installation of package ‘tidyverse’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/rs/dj94tlfj263dzp30z6kvqb5m0000gn/T/RtmpH2BAQU/downloaded_packages’

and for quantmod, I also get two errors:

make: gfortran-4.8: No such file or directory
make: *** [period.max.o] Error 1
ERROR: compilation failed for package ‘xts’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/xts’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/xts’

make: gfortran-4.8: No such file or directory
make: *** [movingAverages.o] Error 1
ERROR: compilation failed for package ‘TTR’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/TTR’
Warning in install.packages :
  installation of package ‘TTR’ had non-zero exit status
ERROR: dependency ‘TTR’ is not available for package ‘quantmod’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/quantmod’

I think it might have to do with my path but I'm not experienced enough to get it to work.

0livier1O1
  • 53
  • 1
  • 9
  • 1
    Have you tried: `brew install libxml2`? (Assuming you use `homebrew`) – Teodor Ciuraru May 08 '18 at 09:00
  • It worked for tidyverse! I actually first had to run "xcode-select --install" for some reason and then use the command you suggested. Thank you. However, it seems to be a different problem for the package Quantmod – 0livier1O1 May 08 '18 at 09:13
  • You need gfortran: https://cran.r-project.org/bin/macosx/tools/ You'll also need libcurl. You should consider installing the binaries from CRAN instead of using homebrew, which installs an outdated version anyway. – Roland May 08 '18 at 10:39
  • I just installed the gfortran 6.1 but it doesn't seem to solve the problem and I have the same errors. I don't understand what's going on here – 0livier1O1 May 08 '18 at 11:49

2 Answers2

1

This was solved for me by uninstalling all versions of R that I had installed via Homebrew with:

brew uninstall --force r

and then re-installing it from CRAN here.

Serenthia
  • 1,222
  • 4
  • 22
  • 40
  • I'm going to try it, I'm using R studio though, should I also uninstall Rstudio ? – 0livier1O1 May 10 '18 at 07:20
  • Nope - RStudio is just an IDE (Integrated Development Environment) but isn’t R itself. R needs to be installed on your system separately, and on MacOS it’s recommended that this comes from CRAN as the Homebrew installation can put things in unexpected places. – Serenthia May 10 '18 at 07:24
  • If you still have gfortran issues, it might be worth checking out another question (& answer) of mine here: https://stackoverflow.com/questions/48866862/cannot-install-stringi-since-xcode-command-line-tools-update which was solved simply by deleting an RStudio config file. – Serenthia May 10 '18 at 07:25
  • 1
    The command you suggested solved both problems I had with quantmod and tidyverse! Thank you! – 0livier1O1 May 10 '18 at 12:20
0

I encountered the same issue. I finally solved it by ref to here

First, manually install lxml2 under instruction of libxml2 web, but had an error when installing:

...
mkdir: /usr/include: Operation not permitted
...

Then changed the prefix to :

./configure --prefix=/usr/local --disable-static --with-history && make
sudo make install

Then install R packages "xml2" again and Ok.

farland
  • 61
  • 1
  • 3