Search code examples
rdylibr-package

R package installation fails cant find existing dylib


Installing R to a custom location (./configure --prefix=$HOME/RTargets/3.3). This goes fine, but install.packages('devtools') fails. The message is:

installing via 'install.libs.R' to /Users/me/Library/R/3.3/library/stringi
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/Users/me/Library/R/3.3/library/stringi/libs/stringi.so':
  dlopen(/Users/me/Library/R/3.3/library/stringi/libs/stringi.so, 6): Library not loaded: libicui18n.58.dylib
  Referenced from: /Users/me/Library/R/3.3/library/stringi/libs/stringi.so
  Reason: image not found
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Users/me/Library/R/3.3/library/stringi’

However, this file exists:

/usr/local/lib>ls -l libicui18n*
-rwxr-xr-x  1 eqiaz44  admin  2679892 Mar  2 23:50 libicui18n.58.1.dylib
lrwxr-xr-x  1 eqiaz44  admin       21 Nov 11 14:14 libicui18n.58.dylib -> libicui18n.58.1.dylib
lrwxr-xr-x  1 eqiaz44  admin       21 Nov 11 14:14 libicui18n.dylib -> libicui18n.58.1.dylib

I'm can't figure out why the loading process for the package can't find the dylib file given that it is in the default location. I can't check how the stringi.so file reference looks since it gets removed.

Is there a way to tell R to NOT remove files when an install fails or some reason why this would happen?


Solution

  • I tried several times to totally remove R and reinstall it with no luck. The issue remained even when not building R as a shared library and using only default configure settings. I confirmed that the solution below worked when building a standard install and a shared library.

    I was able to get this working after seeing the second to last paragraph here

    For whatever reason, the R function dyn.load(...) doesn't appear to use the standard OS (Mac Sierra) library paths. I was able to get it working by modifying the path R uses when loading libraries.

    The top of the script in RHOME/etc/ldpaths looked like this:

    if test -n ""; then 
    : ${R_LD_LIBRARY_PATH=${R_HOME}/lib:}
    else
    : ${R_LD_LIBRARY_PATH=${R_HOME}/lib}
    fi
    

    I added the location with the libraries being loaded, restarted R and the package installed

    if test -n ""; then
    : ${R_LD_LIBRARY_PATH=/usr/local/lib:${R_HOME}/lib:}
    else
    : ${R_LD_LIBRARY_PATH=/usr/local/lib:${R_HOME}/lib}
    fi
    

    The R configure script (I tried this for 3.3.1 and 3.3.2) skips configuring the R library path when it detects Darwin. It has a note in it stating the script assumes the default OS path lookup will happen normally and setting any value would alter its behavior.

    I'm not sure where the disconnect is: is this a bug with dyn.load, a change in the OS behavior, or something else. There may be a better way to resolve this by setting variables during the ./configure or make stages, but I wasn't able to work that out.