Installing R packages in macOS Mojave: Error in if (nzchar(SHLIB_LIBADD))

Viewed 6793

I have been trying to install R packages directly from the terminal but I am struggling much more than setting up the libraries I want in Windows. Sometimes it works if I install every single dependency for more complex packages by downloading them from CRAN and placing them in the R folder. I appreciate this is not efficient but the recurrent error if I run R within the terminal while installing some of the packages is the following:

** libs
Error in if (nzchar(SHLIB_LIBADD)) SHLIB_LIBADD else character() : 
argument is of length zero
* removing ‘/anaconda3/lib/R/library/<package name>’

[...]

In install.packages("<package name>") :
installation of package ‘fpc’ had non-zero exit status

I have been looking across many forums but the only solution I found so far is to install single dependencies manually by downloading them and dropping them in the master R folder. It is taking way longer than expected. Any suggestion will be appreciated. Thanks

3 Answers

in my case (centos 7): /home/xilab/miniconda3/lib/R/etc/Makeconf is a empty file!

find ~ -name Makeconf
/home/xilab/miniconda3/pkgs/r-base-3.6.1-hce969dd_0/lib/R/etc/Makeconf
/home/xilab/miniconda3/pkgs/r-base-3.6.1-h8900bf8_2/lib/R/etc/Makeconf
/home/xilab/miniconda3/envs/python2.7/lib/R/etc/Makeconf
/home/xilab/miniconda3/lib/R/etc/Makeconf

/home/xilab/miniconda3/pkgs/r-base-3.6.1-hce969dd_0/lib/R/etc/Makeconf is not empty,so:

 mv /home/xilab/miniconda3/lib/R/etc/Makeconf /home/xilab/miniconda3/lib/R/etc/Makeconf.backup
 cp /home/xilab/miniconda3/pkgs/r-base-3.6.1-hce969dd_0/lib/R/etc/Makeconf /home/xilab/miniconda3/lib/R/etc/Makeconf

problem solved!

I have seen this problem in conda version of R where /yours/anaconda/environment/lib/R/etc/ has a file Makeconf.mro.original together with an empty Makeconf file. This should not be intended.

During installation of some packages R checks what is within this Makeconf file, one such check is for SHLIB_LIBADD. I just backed up the empty (or whatever) Makeconf file. Then copied Makeconf.mro.original to Makeconf.

This solved my case.

EDIT:

Recently I saw in centos-machine that Makeconf.mro.original file is not made after install.packages("name of library") failed. There is no easy solution for this.

In my case R installation was inside a conda environment. So, I created a new conda environment with R installation. The fresh installation has a Makeconf file in etc directory. So, I copied the Makeconf file from fresh R to my previously working R's etc directory.

It may be better to keep a backup copy of Makeconf from etc to a Makeconf.bak for future problems, in your working R etc directory.

I hope this helps for some cases.

I had this problem when trying to run install.packages("RPostgres") in a conda-installed version of R . The solution was to use conda as the package manager instead of R's install.packages function. That meant running these commands at a normal system command prompt (not in R):

conda search -c conda-forge RPostgres
# shows various versions of r-rpostgres
conda install -c conda-forge r-rpostgres 
Related