R packages break after OS X upgrade

I recently upgraded from OS X 10.10 to 10.11. This has upgraded the version of the gfortran dynamic library from 2 to 3 (in /Library/Frameworks/R.framework/Resources/lib), which in turn causes problems in various R packages (msm, ape).

For those which give an error along the lines of

unable to load shared object

the solution seems to be to use install.packages recursively. Use it on the package that failed. If a dependency fails, use it on that too. Then restart R.

Some packages requiring compilation which link libgfortran (-lgfortran) fail, as the linker line does not give the correct directory through -L. I also have gfortran installed as part of gcc through homebrew, at /Users/john/homebrew/lib/gcc/4.9 (to do this, use ‘brew install gcc’).

Using this, add the line

LDFLAGS=-L/Users/jl11/homebrew/lib/gcc/4.9

to the file ~/.R/Makevars. This should work, as long as when you load the library you have this directory either indexed through OS X’s equivalent of ldconfig (if there is one?), or it is in LD_LIBRARY_PATH.

 

Advertisements
2 comments
  1. jofunu6 said:

    this is also true for bioconductor modules:

    Error in dyn.load(file, DLLpath = DLLpath, …) :
    unable to load shared object ‘/Users/jl11/Library/R/3.2/library/lmtest/libs/lmtest.so’:
    dlopen(/Users/jl11/Library/R/3.2/library/lmtest/libs/lmtest.so, 6): Library not loaded: /Library/Frameworks/R.framework/Versions/3.2/Resources/lib/libgfortran.2.dylib
    Referenced from: /Users/jl11/Library/R/3.2/library/lmtest/libs/lmtest.so
    Reason: image not found

    solution is the same
    source(“https://bioconductor.org/biocLite.R”)
    biocLite(“lmtest”)
    restart R
    repeat

  2. If you have a root install of homebrew, the line in ~/.R/Makevars should be
    LDFLAGS=-L/usr/local/lib/gcc/7
    with ‘7’ replaced with the version of gcc you have installed

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s