14

When I run R I get:

dyld: Library not loaded: /usr/local/opt/openblas/lib/libopenblasp-r0.2.20.dylib
  Referenced from: /usr/local/Cellar/r/3.5.0_1/lib/libR.dylib
  Reason: image not found
Abort trap: 6

Indeed the file is absent:

ls /usr/local/opt/openblas/lib/libopenblasp-r0.2.20.dylib
ls: cannot access '/usr/local/opt/openblas/lib/libopenblasp-r0.2.20.dylib': No such file or directory

I'm on macOS 10.13.3 and used homebrew to install R like this:

# Java
brew cask install java

# OpenBLAS (installs gcc and other dependencies)
brew install openblas

# R language for statistical computing
brew install r --with-openblas --with-java

# Install XQuartz, needed for R package "Cairo"
brew cask install xquartz

# Needed for R package "RMySQL"
brew install mariadb-connector-c

# Needed for R packages: udunits2, units, ggforce
brew install udunits
Kamil Slowikowski
  • 3,157
  • 3
  • 28
  • 33

4 Answers4

16

Let's see if the installed version of openblas is 0.2.20:

brew info openblas 

openblas: stable 0.3.0 (bottled), HEAD [keg-only]
Optimized BLAS library
https://www.openblas.net/
/usr/local/Cellar/openblas/0.3.0 (22 files, 139MB)
  Poured from bottle on 2018-05-31 at 20:42:55
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/openblas.rb
==> Dependencies
Required: gcc ✔
==> Options
--with-openmp
        Enable parallel computations with OpenMP
--HEAD
        Install HEAD version
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BLAS and LAPACK in the Accelerate framework.

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/openblas/lib
    CPPFLAGS: -I/usr/local/opt/openblas/include
For pkg-config to find this software you may need to set:
    PKG_CONFIG_PATH: /usr/local/opt/openblas/lib/pkgconfig

We have 0.3.0 but R is looking for 0.2.20

To fix this, we can create a symlink from the installed dylib:

ln -s /usr/local/opt/openblas/lib/libopenblas.dylib \
      /usr/local/opt/openblas/lib/libopenblasp-r0.2.20.dylib

It works!

R

R version 3.5.0 (2018-04-23) -- "Joy in Playing"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.4.0 (64-bit)
Kamil Slowikowski
  • 3,157
  • 3
  • 28
  • 33
  • 1
    Worked brilliantly also with R 3.5.2_2 and OpenBLAS 0.3.5 (though the version number is different) – AlessioX Jan 13 '19 at 17:29
  • Brilliant! I have the same issue, which even prevent running R in terminals. It turned out my R version 3.6.0 is expecting /usr/local/opt/openblas/lib/libopenblasp-r0.3.6.dylib on the Mac, while somehow I've upgraded it into /usr/local/opt/openblas/lib/libopenblasp-r0.3.7.dylib. So I run ln -s /usr/local/opt/openblas/lib/libopenblas.dylib /usr/local/opt/openblas/lib/libopenblasp-r0.3.7.dylib in terminal and it worked. BTW, this also solve the problem of installing package sf for me. – X.X Nov 26 '19 at 01:52
  • Works like a charm. But it is an odd solution. – Sander W. van der Laan Mar 08 '20 at 22:16
5

Another solution is simply to reinstall R:

brew reinstall r

This will relink R against the correct libraries, and you won't have any symlinks that might get orphaned or cause problems later. This won't affect any R packages you have already installed. Also, if you've already installed the most recent version of R with brew and the bottle is still on your computer then you won't have to download the bottle again.

Simon Bonner
  • 91
  • 1
  • 4
  • while i like the troubleshooting info that Kamil provided, this looks like the correct solution and i just ran it myself. imo we should avoid manual linking solutions like the other one when the tool is gonna solve it for us. – dtc Sep 18 '20 at 17:10
-1

brew upgrade R in most cases will make sure the requirements are installed:

==> Upgrading 1 outdated package:
r 3.5.3 -> 3.6.1
==> Upgrading r
==> Pouring r-3.6.1.mojave.bottle.tar.gz
  /usr/local/Cellar/r/3.6.1: 2,121 files, 56.6MB
Removing: /usr/local/Cellar/r/3.5.3... (2,118 files, 55.8MB)
Justin Shenk
  • 362
  • 3
  • 14
-1

I had a similar error, first for 'libopenblas' and then for 'libgfortran' on Mac OSX 10.14 using R 3.5.2_2.

Solved it by doing:

brew upgrade R

Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/cask and homebrew/bundle).
No changes to formulae.

==> Upgrading 1 outdated package:
r 3.5.2_2 -> 3.6.1
==> Upgrading r 
==> Downloading https://homebrew.bintray.com/bottles/r-3.6.1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/1e/1ed9fe16ae694fa3b35a7d979853447eb7b8aec1e804019a1bf4aafa299a6696?__gd
######################################################################## 100.0%
==> Pouring r-3.6.1.mojave.bottle.tar.gz
  /usr/local/Cellar/r/3.6.1: 2,121 files, 56.6MB
Removing: /usr/local/Cellar/r/3.4.1_2... (2,113 files, 55.2MB)
Removing: /usr/local/Cellar/r/3.5.1... (2,116 files, 55.6MB)
Removing: /usr/local/Cellar/r/3.5.2_2... (2,119 files, 56.0MB)

R works perfectly after that:

R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin18.6.0 (64-bit)
Nate
  • 1