randy3k/radian

Unable to load packages

Closed this issue · 13 comments

I'm on Apple Silicon M1, Big Sur 11.1.
Native R is installed via homebrew.
radian was installed using the default (native) python3 & pip3, but I needed to set:
PYTHONDONTWRITEBYTECODE=1
and install with --user

Radian runs fine and looks great, but I can't seem to load any libraries, which load just fine in default R.

.libPath() is the same for both and R was compiled with --enable-R-shlib.
Below is the error.

r$> library(tidyverse)                                                          
Error: package or namespace load failed for ‘tidyverse’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/homebrew/lib/R/4.0/site-library/vctrs/libs/vctrs.so':
  dlopen(/opt/homebrew/lib/R/4.0/site-library/vctrs/libs/vctrs.so, 6): Library not loaded: /opt/homebrew/opt/r/lib/R/lib/libR.dylib
  Referenced from: /opt/homebrew/lib/R/4.0/site-library/vctrs/libs/vctrs.so
  Reason: image not found

what is the value of R.home() in R? could you also report radian --version

r$> R.home()                                                                    
[1] "/opt/homebrew/lib/R"

radian version: 0.5.9
r executable: /opt/homebrew/lib/R/bin/R
r version: WARNING: ignoring environment value of R_HOME
4.0.3
python executable: /Library/Developer/CommandLineTools/usr/bin/python3
python version: 3.8.2

I guess there may be multiple copies of R in your system and they are not compatible. Could you check what libraries is vctrs.so linking to? Something like,

otool -l /opt/homebrew/lib/R/4.0/site-library/vctrs/libs/vctrs.so

I did go through a lot of different R compiles, playing around with BLAS libraries.
But, at the moment should just have only one R install.
otool output is really long
otool-vctrs-out.txt
I think these are the libraries:
name /opt/homebrew/opt/r/lib/R/lib/libR.dylib (offset 24)
name /opt/homebrew/opt/gettext/lib/libintl.8.dylib (offset 24)
name /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (offset 24)
name /usr/lib/libSystem.B.dylib (offset 24)

For what it's worth, different packages error on different .so files. Here's ggplot2:

r$> library(ggplot2)                                                            
Error: package or namespace load failed for ‘ggplot2’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/homebrew/lib/R/4.0/site-library/colorspace/libs/colorspace.so':
  dlopen(/opt/homebrew/lib/R/4.0/site-library/colorspace/libs/colorspace.so, 6): Library not loaded: /opt/homebrew/opt/r/lib/R/lib/libR.dylib
  Referenced from: /opt/homebrew/lib/R/4.0/site-library/colorspace/libs/colorspace.so
  Reason: image not found

and here is .libPaths()

r$> .libPaths()                                                                 
[1] "/opt/homebrew/lib/R/4.0/site-library"
[2] "/opt/homebrew/lib/R/library"         

and colorspace.so (likewise vctrs.so) are actually located in those locations...

I beleive the error is actually from loading /opt/homebrew/opt/r/lib/R/lib/libR.dylib.
Did you specify R_HOME manually? The warning WARNING: ignoring environment value of R_HOME is bugging me.

Honestly, I'm not sure?
I may have set it manually while trying to get VS Code to work?
I tried unsetting it:

>./radian --version  
radian version: 0.5.9
r executable: /opt/homebrew/Cellar/r-blas/4.0.3_1/lib/R/bin/R
r version: 4.0.3
python executable: /Library/Developer/CommandLineTools/usr/bin/python3
python version: 3.8.2

Alas, same error:

r$> library(tidyverse)                                                          
Error: package or namespace load failed for ‘tidyverse’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/homebrew/lib/R/4.0/site-library/vctrs/libs/vctrs.so':
  dlopen(/opt/homebrew/lib/R/4.0/site-library/vctrs/libs/vctrs.so, 6): Library not loaded: /opt/homebrew/opt/r/lib/R/lib/libR.dylib
  Referenced from: /opt/homebrew/lib/R/4.0/site-library/vctrs/libs/vctrs.so
  Reason: image not found

Wait, I see what you mean.
/opt/homebrew/opt/r/lib/R/lib/libR.dylib
Is wrong, it should be:
/opt/homebrew/lib/R/lib/libR.dylib

I guess I need to try to reinstall?
Odd that it works in regular R...

Ah! More clarity. I'm using a custom brew formula, named r-blas.
I had the regular R formula, but switched.
/opt/homebrew/opt/ doesn't have a R dir (symlink), instead it has R-blas
I'll try duplicating the symlink...

my bad, it should be

otool -L /opt/homebrew/lib/R/4.0/site-library/vctrs/libs/vctrs.so

could you try again?

Does the file /opt/homebrew/opt/r/lib/R/lib/libR.dylib exist at all?

The error is raised when vctrs.so loads libR.dylib and for some reason, it cannot be loaded.

Success!

r$> library(tidyverse)                                                          
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
✔ ggplot2 3.3.2     ✔ purrr   0.3.4
✔ tibble  3.0.4     ✔ dplyr   1.0.2
✔ tidyr   1.1.2     ✔ stringr 1.4.0
✔ readr   1.4.0     ✔ forcats 0.5.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()


For
otool -L /opt/homebrew/lib/R/4.0/site-library/vctrs/libs/vctrs.so
I get

/opt/homebrew/lib/R/4.0/site-library/vctrs/libs/vctrs.so:
	vctrs.so (compatibility version 0.0.0, current version 0.0.0)
	/opt/homebrew/opt/r/lib/R/lib/libR.dylib (compatibility version 4.0.0, current version 4.0.3)
	/opt/homebrew/opt/gettext/lib/libintl.8.dylib (compatibility version 11.0.0, current version 11.0.0)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1770.255.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.60.1)

I'm glad that you figure it out. Homebrew has a mechanism to fix this rpath issue for the official R formula, I guess your custom formula didn't fix it.

Success!

r$> library(tidyverse)                                                          
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
✔ ggplot2 3.3.2     ✔ purrr   0.3.4
✔ tibble  3.0.4     ✔ dplyr   1.0.2
✔ tidyr   1.1.2     ✔ stringr 1.4.0
✔ readr   1.4.0     ✔ forcats 0.5.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()

Thank you for your time and patience.
If there is anything you'd like tested on Apple Silicon M1 MacOS Big Sur, please let me know.
Now I get to play with configuration!